pop & popFront combined
    Jakob Ovrum via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sat Nov  1 09:10:16 PDT 2014
    
    
  
On Saturday, 1 November 2014 at 11:43:28 UTC, Nordlöw wrote:
> On Saturday, 20 September 2014 at 19:23:46 UTC, Jakob Ovrum 
> wrote:
>> If you want move semantics, use `moveFront`.
>
> But x.moveFront doesn't modify x.
It does modify `x` as it leaves `front` in a destroyed and 
default-initialized state, as required by move semantics.
> What I want is to transform my uses of std.range from
>
> if (!x.empty)
> {
>     x.front.doStuff;
>     x.popFront;
> }
>
> into
>
> if (!x.empty)
>     if (auto front = x.stealFront)
>     {
>         front.doStuff;
>     }
>
> This is more functional/atomic, that is it reduces the risk of 
> accidentally forgetting to call popFront at the end.
>
> Destroy!
The other half of my post explained why such a `stealFront` is 
problematic.
    
    
More information about the Digitalmars-d-learn
mailing list