On Saturday, 20 September 2014 at 18:59:03 UTC, Nordlöw wrote:
Is there a reason why popFront doesn't automatically return what front does?

If so I'm still missing a combined variant of pop and popFront in std.range.
Why isn't such a common operation in Phobos already?

So far I know isn't common use return value from popFront() at same time it's called. For example, checkout how is:

int[] a = [1,2,3];
foreach(int n; a) {}

is translated:

for(auto r = a; !r.empty; r.popFront())
{
  int n = r.front;
}

to return same as value in front by popFront() save previously value is needed:

int popFrontInt(out int[] arr)
{
   int current = arr[0]; // or arr.front
   arr = arr[1 .. $];
   return current;
}

(this isn't exactly like Phobos implementation and is int[]-only, btw)

the cost of the 'current' variable may be a bit expansive (one extra register use per function call) and useless, since it isn't used and a common use is one like the loop.

I think it's well-designed, IMHO...

On Saturday, 20 September 2014 at 18:59:03 UTC, Nordlöw wrote:
If you want move semantics, use `moveFront`.

Is this function part of phobos library? if so, where?

Reply via email to