<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thanks to Ole Begemann (who closed my bug report), I found out that Nate Cook submitted a <a href="https://github.com/apple/swift/pull/4896" class="">fix</a> for this issue a few day ago. The fix will hopefully make it to the next maintenance release of Swift.<div class=""><br class=""></div><div class="">The documentation of range subscript (which is the main API for creating subsequences) already specifies that SubSequences (slices) should use the same indices, but I think we need to better document the specifications of SubSequence associated type and make sure that any API that returns a SubSequence links to SubSequence documentation.</div><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 16, 2016, at 3:33 PM, Dave Abrahams via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">on Thu Oct 13 2016, Tim Vermeulen <<a href="http://swift-users-AT-swift.org" class="">swift-users-AT-swift.org</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">Is it a requirement that collections share indices with its<br class="">subsequence? <br class=""></blockquote><br class="">Yes.<br class=""><br class=""><blockquote type="cite" class="">Array and ArraySlice do share indices, which is why ArraySlice isn’t<br class="">zero-based, and I think this is convenient. But String.CharacterView<br class="">doesn’t seem to share indices with its subsequence (which is<br class="">String.CharacterView as well). <br class=""></blockquote><br class="">That's a bug.<br class=""><br class=""><blockquote type="cite" class="">Consider this example:<br class=""><br class="">let foo = "foobar".characters<br class=""><br class="">let index = foo.index(foo.startIndex, offsetBy: 3)<br class="">let bar = foo.suffix(from: index) // "bar"<br class=""><br class="">foo[index] // "b" :)<br class="">foo[bar.startIndex] // "f" :(<br class=""><br class="">So does this mean that we can’t assume that collections and their<br class="">subsequences share their indices (which could be very handy), or is<br class="">this just a bug related to String.CharacterView?<br class=""></blockquote><br class="">The latter.<br class=""><br class="">-- <br class="">-Dave<br class=""><br class="">_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></div></blockquote></div><br class=""></div></div></body></html>