String should be some kind of MutableCollection. if we really want to restrict subscript of String should be { get } only, then we should consider make some extension methods of MutableCollection should available on SubrangeReplaceablecollection too.
For example: > > var c = [1, 2, 3, 4] > print(c.reversed()) // OK > > > var d = "1234" > print(d.reversed()) // OK They are both fine. > var a = [1, 2, 3, 4] > a.reverse() > print(a) // OK > > > var b = "1234" > b.reverse() // no function > print(b) But this is weird. String has String.reversed() function, but it does not have String.reverse() function which is MutableCollection only. I think, MutableCollection.reverse(), swapAt(_:_:), .partition(by:), sort(by:), should also be available with RangeReplaceableCollection. > 在 2017年12月6日,06:55,Dave Abrahams <dabrah...@apple.com> 写道: > > > > Sent from my iPhone > >> On Dec 5, 2017, at 12:19 AM, Cao, Jiannan via swift-dev >> <swift-dev@swift.org> wrote: >> >> >> But, I mean, what subscript (restrict to the length) could do is subset of p >> replaceSubrange could do, right? > > True but that would imply the opposite of the refinement relationship you’re > suggesting. A derived protocol has to have a subset of the behavior of the > protocol it refines.
_______________________________________________ swift-dev mailing list swift-dev@swift.org https://lists.swift.org/mailman/listinfo/swift-dev