[swift-evolution] Shouldn't ".withUnsafeBufferPointer" and ".withUnsafeMutableBufferPointer" be parts of protocols?
Dave Abrahams
dabrahams at apple.com
Sun Jan 29 03:23:22 CST 2017
on Sun Jan 29 2017, Dave Abrahams <swift-evolution at swift.org> wrote:
> on Sat Jan 28 2017, Brent Royal-Gordon <brent-AT-architechies.com> wrote:
>
>>> 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 }
>> }
>
> Maybe, if we had the language feature, we could do that... but we don't.
>
>> 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) }
>> }
>
> That's not actually helpful, because segmented algorithms need to be
> able to use the presence of segments to stop recursing :-)
Er, the absence of segments I mean.
--
-Dave
More information about the swift-evolution
mailing list