mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
It is no longer necessary to produce `.swiftinterface` files the support older compilers that lack support for the NoncopyableGenerics feature. Cleaning this up makes the stdlib `.swiftinterface` far more readable.
35 lines
727 B
Swift
35 lines
727 B
Swift
|
|
public protocol Generator<Value> {
|
|
associatedtype Value
|
|
mutating func next() -> Value?
|
|
}
|
|
|
|
public struct Counter: Generator {
|
|
var state: Int = 0
|
|
public mutating func next() -> Int? {
|
|
let value = state
|
|
state += 1
|
|
return value
|
|
}
|
|
}
|
|
|
|
public func advance<T: Generator>(by n: Int, _ t: inout T) {
|
|
for _ in 0..<n {
|
|
_ = t.next()
|
|
}
|
|
}
|
|
|
|
public enum Maybe<Wrapped: ~Copyable>: ~Copyable {
|
|
case just(Wrapped)
|
|
case none
|
|
}
|
|
|
|
extension Maybe: Copyable where Wrapped: Copyable {}
|
|
|
|
public func ncIdentity<T: ~Copyable>(_ t: consuming T) -> T { return t }
|
|
|
|
public protocol Either<Left, Right>: ~Copyable {
|
|
associatedtype Left: ~Copyable
|
|
associatedtype Right: ~Copyable
|
|
}
|