Files
swift-mirror/test/Serialization/Inputs/ncgenerics.swift
Kavon Farvardin ec4a125f3e NCGenerics: ext's might not infer invertible req's
If the extension adds conformance to an invertible protocol, it's
confusing for people to also infer conditional requirements on the
generic parameters for those invertible protocols. This came up in the
review of SE-427.
2024-06-12 14:44:22 -07:00

38 lines
760 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()
}
}
#if $NoncopyableGenerics
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
}
#endif