On 12/01/2017 01:11 AM, Johan Engelen wrote:

I tested it and it works like you wrote, but the behavior is different for an array of integers...:

auto a = [ 1,2,3 ];
writeln(a.front); // 1
auto b = a.moveFront();
writeln(b); // 1
writeln(a.length); // still 3
writeln(a.front); // still 1

-Johan

Good catch, which affects my struct S example as well.

It's a documentation bug as it does not mention different behavior depending on elaborate copy constructor:

  https://github.com/dlang/phobos/blob/master/std/range/primitives.d#L1848

ElementType!R moveFront(R)(R r)
{
    static if (is(typeof(&r.moveFront)))
    {
        return r.moveFront();
    }
    else static if (!hasElaborateCopyConstructor!(ElementType!R))
    {
        return r.front;
    }
    else static if (is(typeof(&(r.front())) == ElementType!R*))
    {
        import std.algorithm.mutation : move;
        return move(r.front);
    }
    else
    {
        static assert(0,
"Cannot move front of a range with a postblit and an rvalue front.");
    }
}

Ali

Reply via email to