Enum member isRandomAccessRange
Determines whether R is a random-access range.
enum isRandomAccessRange(R)
= isInputRange!R && (hasLength!R || isInfinite!R) && (U() == Primitive!(R, "front()")());
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.
Parameters
Name | Description |
---|---|
R | The type to be tested. |
Returns
true if R is a random-access range, false otherwise.
See Also
isInfinite, hasLength.
Note
This definition differs from std
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 isForwardRange and
isBidirectionalRange.
Example
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);