isRandomAccessRange

Determines whether R is a random-access range.

A random-access range is a range that allows random access to its elements by index using []-operator (defined with opIndex()). Further a random access range should have a length or be infinite.

Members

Variables

isRandomAccessRange
enum bool isRandomAccessRange;
Undocumented in source.
isRandomAccessRange
enum bool isRandomAccessRange;
Undocumented in source.

Parameters

R

The type to be tested.

Return Value

$(D_KEYWORD true) if R is a random-access range, $(D_KEYWORD false) otherwise.

Examples

static struct A
{
    void popFront() @nogc nothrow pure @safe
    {
    }

    @property int front() @nogc nothrow pure @safe
    {
        return 0;
    }

    bool empty() const @nogc nothrow pure @safe
    {
        return true;
    }

    int opIndex(size_t) @nogc nothrow pure @safe
    {
        return 0;
    }

    size_t length() const @nogc nothrow pure @safe
    {
        return 0;
    }
}
static assert(isRandomAccessRange!A);
static assert(isRandomAccessRange!(int[]));
static assert(!isRandomAccessRange!(void[]));

static struct B
{
    void popFront() @nogc nothrow pure @safe
    {
    }

    @property int front() @nogc nothrow pure @safe
    {
        return 0;
    }

    enum bool empty = false;

    int opIndex(const size_t pos) @nogc nothrow pure @safe
    {
        return 0;
    }
}
static assert(isRandomAccessRange!B);

See Also

$(D_PSYMBOL isInfinite), $(D_PSYMBOL hasLength).

Note: This definition differs from std.range.primitives.isRandomAccessRange in the D standard library in that it does not also require R to be a forward range and a bidirectional range. Those properties may be tested separately with $(D_PSYMBOL isForwardRange) and $(D_PSYMBOL isBidirectionalRange).

Meta