Should this work?

Iain Buclaw ibuclaw at gdcproject.org
Sat Jan 11 04:49:15 PST 2014


On 11 January 2014 01:37, Manu <turkeyman at gmail.com> wrote:
> On 11 January 2014 05:57, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>>
>> On 1/10/14 7:23 AM, Manu wrote:
>>>
>>> This is what I've done. I'm just surprised that such an obvious function
>>> doesn't exist, and suspect I was just retarded at phobos again.
>>> Having a function that does this is kinda important to simplify lots of
>>> expressions that otherwise need to be broken out across a bunch of lines.
>>
>>
>> I doubt it simplifies a lot.
>
>
> 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.
> Yes, it really does simplify many expressions.
>
> I'm working on something where I go along munching tokens from the stream,
> and performing fairly arbitrary sequential logic on them.
> 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.
>
> It sucks particularly when there's 'if's involved:
>
> if(r.front == x)
> {
>   r.popFront();
>   x = r.front();
>   r.popFront();
> }
> else
> {
>   r.popFront();
>   y = r.front();
>   r.popFront();
> }
>
>
> Surely this is obviously better:
>
> if(r.getAndPopFront() == x)
>   x = r.getAndPopFront();
> else
>   y = r.getAndPopFront();
>

I recall mentioning something like this, way back in 2011 - possibly
in IRC.  People like the idea, no one actually sat down and wrote it.
:-)

Regards
Iain


More information about the Digitalmars-d mailing list