[swift-evolution] [Pitch] Removing the empty initialiser requirement from RangeReplaceableCollection

Tim Vermeulen tvermeulen at me.com
Mon Jul 11 16:36:21 CDT 2016


> on Wed Jul 06 2016, Tim Vermeulen<swift-evolution at swift.org>wrote:
> 
> > This is a follow up from this swift-users thread: https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160704/002489.html
> > 
> > As it stands, RangeReplaceableCollection requires an implementation
> > for init(), which is used in the default implementations of (as far as
> > I can tell) init(_:), init(repeating:count:) and
> > removeAll(keepingCapacity:). The latter of these methods should be
> > implementable with removeSubrange(_:) instead.
> You can't implement `removeAll(keepingCapacity: false)` with
> `removeSubrange(_:)`. How do you propose to provide the other default
> implementations?

You’re right, I didn’t think that through properly. My first thought was a copy constructor for collections in general, but as you pointed out, this wouldn’t be efficient for this purpose. An “empty copy constructor” would be better, which could be either a static method, an instance method, a computed property or an initialiser. I’d probably opt for the computed property (it will always run in O(1) anyways, I think), but it doesn’t really matter.

> > I would like to propose to *remove* all three initialisers from this
> > protocol, because it makes it impossible for some collections to
> > conform to it that need extra data for its initialisation, but are
> > otherwise perfectly capable of having arbitrary subranges replaced by
> > elements from another collection.
> I agree with the goal, but I'd like to see an implementation before I
> agree that it's acheivable.
> 
> > Those three initialisers could
> > either move to a new protocol or simply not be part of any protocol.
> > 
> > 
> > On a similar note, I’d like to have all initialisers of SetAlgebra removed as well, but that might need its own review.
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
> --
> Dave
> 
> 
> 
> 


More information about the swift-evolution mailing list