<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></div><div>Probably needs an argument label since it's performing an explicit purpose, not just a vanilla conversion initializer. So maybe UnsafeRawBufferPointer.init(rebasing:)</div><div><br></div><div>Or since we have same-type constrained extensions now on master maybe you could do it as a property<span style="background-color: rgba(255, 255, 255, 0);">:</span>&nbsp;</div><div><br></div><div><p style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"><span style="font-variant-ligatures: no-common-ligatures;">extension</span><span style="font-variant-ligatures: no-common-ligatures;">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;">RandomAccessSlice</span><span style="font-variant-ligatures: no-common-ligatures;">&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;">where</span><span style="font-variant-ligatures: no-common-ligatures;">&nbsp;Base == UnsafeRawBufferPointer {</span></span></p><p style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"><span style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;">var</span><span style="font-variant-ligatures: no-common-ligatures;">&nbsp;rebased:&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;">UnsafeRawBufferPointer</span><span style="font-variant-ligatures: no-common-ligatures;">&nbsp;{</span></span></p><p style="margin: 0px; line-height: normal;"><span style="background-color: rgba(255, 255, 255, 0);"><span style="font-variant-ligatures: no-common-ligatures;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span style="font-variant-ligatures: no-common-ligatures;">return</span><span style="font-variant-ligatures: no-common-ligatures;">&nbsp;UnsafeRawBufferPointer(start: base.baseAddress, count: count)</span></span></p><p style="margin: 0px; line-height: normal;"><span style="font-variant-ligatures: no-common-ligatures; background-color: rgba(255, 255, 255, 0);">&nbsp; &nbsp; }</span></p><p style="margin: 0px; line-height: normal;"><span style="font-variant-ligatures: no-common-ligatures; background-color: rgba(255, 255, 255, 0);">}</span></p><p style="margin: 0px; line-height: normal;"><span style="font-variant-ligatures: no-common-ligatures; background-color: rgba(255, 255, 255, 0);"><br></span></p><p style="margin: 0px; line-height: normal;"><span style="font-variant-ligatures: no-common-ligatures; background-color: rgba(255, 255, 255, 0);"></span></p><div><span style="background-color: rgba(255, 255, 255, 0);">(written by hand without a compiler so unlikely to be correct :)</span></div></div><div><br>On Dec 8, 2016, at 18:07, Andrew Trick &lt;<a href="mailto:atrick@apple.com">atrick@apple.com</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 8, 2016, at 5:44 PM, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Thu, Dec 8, 2016 at 6:53 PM, Ben Cohen via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><span class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 8, 2016, at 4:35 PM, Jordan Rose via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_4897115594286405450Apple-interchange-newline"><div class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">Um, Sequence doesn’t have a subscript (or indexes). Sequences are single-pass. So if this is important, it needs to stay a Collection.</div><br class="m_4897115594286405450Apple-interchange-newline"></div></blockquote></div><br class=""></span><div class="">Just because something fulfills one of the requirements of a Collection does not mean it should be one. It needs to tick all the boxes before its allowed to be elevated.</div><div class=""><br class=""></div><div class="">But it’s still allowed to have subscripts (UnsafePointer has subscripting but isn’t a collection) or be multi-pass (strides are multiples but are only sequences). That’s OK</div><div class=""><br class=""></div><div class="">In this case, yes it’s multi-pass, yes it has a subscript, but no it isn’t a collection because it doesn’t meet the requirements for slicing i.e. that indices of the slice be indices of the parent.</div><div class="">(relatedly… it appears this requirement is documented on the concrete Slice type rather than on Collection… which is a documentation bug we should fix).</div></div></blockquote><div class=""><br class=""></div><div class="">If this is indeed a requirement for Collection, then my vote would be for Nate's option #1 and Andy's option #2, to give UnsafeRawBufferPointer a Slice type that fulfills the requirement. It's the smallest change, preserves the use of integer indices, and preserves what Andy stated as the desired use case of making it easy for users to switch out code written for [UInt8].</div></div></div></div></div></blockquote><br class=""></div><div>Ok, but there needs to be an easy way in a nongeneric context to convert from a Slice&lt;URBP&gt; into an URBP (with normalized byte offsets).</div><div><br class=""></div><div>Does anyone object to adding an initializer for this? Any suggestions on naming? Do we need an argument label? etc?</div><div><br class=""></div><div>UnsafeRawBufferPointer(_ : Slice&lt;UnsafeRawBufferPointer&gt;)</div><div><br class=""></div><div>as in:</div><div><br class=""></div><div>let region = UnsafeRawBufferPointer(buffer[i..&lt;j])</div><div><br class=""></div><div>-Andy</div></div></blockquote></div></body></html>