> On Jan 19, 2017, at 19:38, David Sweeris <daveswee...@mac.com> wrote:
> 
> Regarding substrings... Instead of having separate `ArraySlice` and 
> `Substring` types, what about having just one type, `Slice<T: Sequence>`, for 
> anything which shares memory? Seems like it'd be easier for users who'd only 
> have to worry about shared storage for one type, and for stdlib authors who'd 
> only have to write it once.

Collections already do get a default SubSequence implementation of Slice<Base: 
Indexable> that is essentially like just that. 

The reason types like Array and String have their own is to customize it with 
more than the default behavior. For example, ArraySlice provides 
.withUnsafeBufferPointer  method just like an Array does. Substring would need 
all the features String provides.

Now, once we get conditional conformance, we could use that to maybe increase 
sharing, for example we could create a protocol for types backed by contiguous 
memory that provided withUnsafeEtc, and then use conditional conformance to add 
those features to Slice when the Base has them. This probably won't improve 
user experience particularly though, just help library authors 
organize/minimize the code.

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to