<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 11 January 2014 05:57, Andrei Alexandrescu <span dir="ltr"><<a href="mailto:SeeWebsiteForEmail@erdani.org" target="_blank">SeeWebsiteForEmail@erdani.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">On 1/10/14 7:23 AM, Manu wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
This is what I've done. I'm just surprised that such an obvious function<br>
doesn't exist, and suspect I was just retarded at phobos again.<br>
Having a function that does this is kinda important to simplify lots of<br>
expressions that otherwise need to be broken out across a bunch of lines.<br>
</blockquote>
<br></div>
I doubt it simplifies a lot.</blockquote><div><br></div><div>Well you can pass it as an argument, or use it as a term in an expression without splitting it across a whole bunch of lines.</div><div>Yes, it really does simplify many expressions.</div>
<div><br></div><div>I'm working on something where I go along munching tokens from the stream, and performing fairly arbitrary sequential logic on them.</div><div>My code would be almost twice as long if I needed a second line to advance the range after each line where I consider the front token's value.<br>
</div><div><br></div><div>It sucks particularly when there's 'if's involved:</div><div><br></div><div>if(r.front == x)</div><div>{</div><div>  r.popFront();</div><div>  x = r.front();</div><div>  r.popFront();</div>
<div>}<br></div><div>else</div><div>{</div><div>  r.popFront();</div><div>  y = r.front();</div><div>  r.popFront();</div><div>}</div><div><br></div><div><br></div><div>Surely this is obviously better:</div><div><br></div>
<div>if(r.getAndPopFront() == x)</div><div>  x = r.getAndPopFront();</div><div>else<br></div><div>  y = r.getAndPopFront();</div><div><br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Does nobody see this coming up in their code? I have it basically every<br>
time I use ranges, and as usual, surprised others don't feel the same way.<br>
</blockquote>
<br></div>
If it would have been frequent, it would have been a common request. Apparently it isn't. Even before ranges there wasn't a function that got you s[0] and also assigned s = s[1 .. $] in one shot, and that wasn't asked for either.</blockquote>
<div><br></div><div>I agree. Which is why I asked for it here before writing my own; I assumed it must already exist, it would have been asked for before...</div></div></div></div>