[swift-evolution] Shouldn't ".withUnsafeBufferPointer" and ".withUnsafeMutableBufferPointer" be parts of protocols?
Brent Royal-Gordon
brent at architechies.com
Sun Jan 29 01:58:29 CST 2017
> On Jan 28, 2017, at 11:48 AM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>
> The way to handle Deque is to add this requirement to Collection when
> we get the language features to express it:
>
> protocol Collection {
>
> associatedtype Segments : Collection
> where Segments.Element : Collection,
> Segments.Element.Element == Element
> = EmptyCollection<EmptyCollection<Element>>
>
> var segments: Segments? {get}
> ...
> }
>
> extension Collection
> where Segments == EmptyCollection<EmptyCollection<Element>> {
> var segments: Segments? { return nil }
> }
Couldn't that be be expressed more accurately with `Never` if it were a subtype-of-all-types?
protocol Collection {
associatedtype Segments : Collection
where Segments.Element : Collection,
Segments.Element.Element == Element
= Never
var segments: Segments? {get}
...
}
extension Collection
where Segments == Never {
var segments: Segments? { return nil }
}
Or you could say that there is always at least *one* segment:
protocol Collection {
associatedtype Segments : Collection
where Segments.Element : Collection,
Segments.Element.Element == Element
= CollectionOfOne<Self>
var segments: Segments {get}
...
}
extension Collection
where Segments == CollectionOfOne<Self> {
var segments: Segments { return CollectionOfOne(self) }
}
--
Brent Royal-Gordon
Architechies
More information about the swift-evolution
mailing list