Enum member hasMobileElements

Determines whether R is a range containing mobile elements, i.e. elements that can be moved out of the range.

enum hasMobileElements(R) = is(typeof((R r) => moveFront(r))) && is(typeof((R r) => moveAt(r, 0)));

Having mobile elements means for an input range to support moveFront, for a bidirectional range - both, moveFront and moveBack, for a random-access range - moveFront and moveAt.

Parameters

NameDescription
R Range type.

Returns

true if R has mobile elements, false otherwise.

See Also

moveFront, moveBack, moveAt.

Example

static assert(hasMobileElements!(int[]));

Example

static struct Element
{
    this(this) @nogc nothrow pure @safe
    {
    }
}

static struct R1
{
    enum bool empty = false;

    Element front() @nogc nothrow pure @safe
    {
        return Element();
    }

    void popFront() @nogc nothrow pure @safe
    {
    }
}
static assert(!hasMobileElements!R1);

static struct R2
{
    enum bool empty = false;
    private Element front_;

    ref Element front() @nogc nothrow pure @safe
    {
        return front_;
    }

    void popFront() @nogc nothrow pure @safe
    {
    }
}
static assert(hasMobileElements!R2);