<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 29, 2017 at 4:13 PM, Andrew Trick <span dir="ltr">&lt;<a href="mailto:atrick@apple.com" target="_blank">atrick@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><span class=""><br><div><br><blockquote type="cite"><div>On Sep 29, 2017, at 1:23 PM, Taylor Swift &lt;<a href="mailto:kelvin13ma@gmail.com" target="_blank">kelvin13ma@gmail.com</a>&gt; wrote:</div><br class="m_1404466990729912635Apple-interchange-newline"><div><blockquote class="gmail_quote" 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;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><div><div>Instead of</div><div><br></div><div> <span class="m_1404466990729912635Apple-converted-space"> </span>buf.intialize(at: i, from: source)</div><div><br></div><div>We want to force a more obvious idiom:</div><div><br></div><div> <span class="m_1404466990729912635Apple-converted-space"> </span>buf[i..&lt;n].intialize(from: source)</div><div><br></div></div></div></div></blockquote><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"><br></div><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">The problem with subscript notation is we currently get the<span class="m_1404466990729912635Apple-converted-space"> </span><span style="font-family:monospace,monospace">n</span><span class="m_1404466990729912635Apple-converted-space"> </span>argument from the<span class="m_1404466990729912635Apple-converted-space"> </span><span style="font-family:monospace,monospace">source</span><span class="m_1404466990729912635Apple-converted-space"> </span>argument. So what would really have to be written is<span class="m_1404466990729912635Apple-converted-space"> </span><br></div><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"><br></div><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"><span style="font-family:monospace,monospace">buf[i ..&lt; i + source.count].initialize(from: source)<span class="m_1404466990729912635Apple-converted-space"> </span></span><br></div><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"><br></div><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">which is a lot more ugly and redundant. One option could be to decouple the count parameter from the length of the source buffer, but that opens up the whole can of worms in which length do we use? What happens if<span class="m_1404466990729912635Apple-converted-space"> </span><span style="font-family:monospace,monospace">n - i</span><span class="m_1404466990729912635Apple-converted-space"> </span>is less than or longer than<span class="m_1404466990729912635Apple-converted-space"> </span><span style="font-family:monospace,monospace">source.count</span>? If we enforce the precondition that<span class="m_1404466990729912635Apple-converted-space"> </span><span style="font-family:monospace,monospace">source.count == n - i</span>, then this syntax seems horribly redundant.<span class="m_1404466990729912635Apple-converted-space"> </span></div></div></blockquote></div><br></span><div>Sorry, a better analogy would have been:</div><div><br></div><div><div style="word-wrap:break-word;line-break:after-white-space"><div><div><div> buf[i...].intialize(from: source)</div><div><br></div><div>Whether you specify the slice’s end point depends on whether you want to completely initialize that slice or whether you’re just filling up as much of the buffer as you can. It also depends on whether `source` is also a buffer (of known size) or some arbitrary Sequence.</div><div><br></div><div>Otherwise, point  taken.</div><div><br></div><div>-Andy</div></div></div></div></div></div></blockquote><div><br></div><div>After thinking about this more, one-sided ranges might provide just the expressivity we need. What if:</div><div><br></div><div><span style="font-family:monospace,monospace"> buf[offset...].initialize(from: source) // initializes source.count elements from source starting from offset</span></div><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">buf[offset ..&lt; endIndex].initialize(from: source) // initializes up to source.count elements from source starting from offset<br></span></div><div><br></div><div><br></div></div>The one sided one does not give a full initialization guarantee. The two sided one guarantees the entire segment is initialized. For move operations, the one sided one will fully deinitialize the source buffer while the two sided one will only deinitialize <span style="font-family:monospace,monospace">endIndex - offset</span> elements. <br></div></div>