View source code Display the source code in std/range/primitives.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

Enum std.range.primitives.member hasAssignableElements

Returns true if R is an input range and has mutable elements. The following code should compile for any range with assignable elements.

R r;
static assert(isInputRange!R);
r.front = r.front;
static if (isBidirectionalRange!R) r.back = r.front;
static if (isRandomAccessRange!R) r[0] = r.front;

Declaration

enum hasAssignableElements(R) = isInputRange!R && is(typeof((inout int = 0)
{
R r = R.init;
r.front = r.front;
static if (isBidirectionalRange!R)
{
r.back = r.front;
}

static if (isRandomAccessRange!R)
{
r[0] = r.front;
}

}
));

Example

static assert(!hasAssignableElements!(const int[]));
static assert(!hasAssignableElements!(const(int)[]));
static assert( hasAssignableElements!(int[]));
static assert(!hasAssignableElements!(inout(int)[]));

static assert(!hasAssignableElements!( string));
static assert(!hasAssignableElements!(dstring));
static assert(!hasAssignableElements!( char[]));
static assert( hasAssignableElements!(dchar[]));

Authors

Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.

License

Boost License 1.0.

Comments