mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
35 lines
779 B
Swift
35 lines
779 B
Swift
// RUN: %target-swift-frontend -emit-ir %s
|
|
|
|
protocol Tuple {
|
|
associatedtype Head
|
|
associatedtype Tail : Tuple
|
|
}
|
|
|
|
extension Pair : Tuple where Second : Tuple {
|
|
typealias Head = First
|
|
typealias Tail = Second
|
|
}
|
|
|
|
protocol HomogeneousTuple : Tuple, Collection
|
|
where Tail : HomogeneousTuple, Head == Tail.Head {}
|
|
|
|
extension HomogeneousTuple {
|
|
typealias Element = Head
|
|
typealias Index = Int
|
|
|
|
var startIndex: Int { return 0 }
|
|
var endIndex: Int { return 0 }
|
|
func index(after i: Int) -> Int { return i + 1 }
|
|
|
|
subscript(n: Int) -> Head {
|
|
fatalError()
|
|
}
|
|
}
|
|
|
|
extension Pair : Sequence, Collection, HomogeneousTuple
|
|
where Second : HomogeneousTuple, First == Second.Head {
|
|
typealias Iterator = IndexingIterator<Pair<Head, Tail>>
|
|
}
|
|
|
|
struct Pair<First, Second> {}
|