mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
20 lines
490 B
Swift
20 lines
490 B
Swift
// Adopt ForwardIndex via BidirectionalIndex.
|
|
public struct Counter<T: protocol<RandomAccessIndex, IntegerLiteralConvertible>> : BidirectionalIndex {
|
|
public var value = 0
|
|
|
|
public func predecessor() -> Counter {
|
|
return Counter(value: value - 1)
|
|
}
|
|
|
|
public func successor() -> Counter {
|
|
return Counter(value: value + 1)
|
|
}
|
|
|
|
public init(value: Int) { self.value = value }
|
|
}
|
|
|
|
public func == <T>(lhs: Counter<T>, rhs: Counter<T>) -> Bool {
|
|
return lhs.value == rhs.value
|
|
}
|
|
|