<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div><br></div>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.<div><br></div><div>For example:</div><blockquote type="cite"><div><br></div><div><div><div><span style="background-color: rgba(255, 255, 255, 0);">var c = [1, 2, 3, 4]</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">print(c.reversed()) // OK</span></div></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">var d = "1234"</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">print(d.reversed()) // OK</span></div></div></blockquote><div><br></div><div>They are both fine.</div><div><br></div><div><blockquote type="cite"><div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">var a = [1, 2, 3, 4]</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">a.reverse()</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">print(a) // OK</span></font></div></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);"><br></span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">var b = "1234"</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">b.reverse() // no function</span></font></div><div><font color="#000000"><span style="background-color: rgba(255, 255, 255, 0);">print(b)</span></font></div></blockquote><br></div><div>But this is weird.</div><div><br></div><div>String has String.reversed() function,</div><div>but it does not have String.reverse() function which is MutableCollection only.</div><div><br></div><div><br></div><div>I think, MutableCollection.reverse(), swapAt(_:_:), .partition(by:), sort(by:), should also be available with RangeReplaceableCollection.</div><div><br><div>在 2017年12月6日,06:55,Dave Abrahams <<a href="mailto:dabrahams@apple.com">dabrahams@apple.com</a>> 写道:<br><br></div><blockquote type="cite"><div><span></span><br><span></span><br><span>Sent from my iPhone</span><br><span></span><br><blockquote type="cite"><span>On Dec 5, 2017, at 12:19 AM, Cao, Jiannan via swift-dev <<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>> wrote:</span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span></span><br></blockquote><blockquote type="cite"><span>But, I mean, what subscript (restrict to the length) could do is subset of p replaceSubrange could do, right?</span><br></blockquote><span></span><br><span>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. </span></div></blockquote></div></div></body></html>