View source code
Display the source code in std/range/primitives.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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.

Enum member std.range.primitives.hasAssignableElements

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

enum hasAssignableElements(R) = isInputRange!R && is(typeof(lvalueOf!R.front = lvalueOf!R.front)) && (!isBidirectionalRange!R || is(typeof(lvalueOf!R.back = lvalueOf!R.back))) && (!isRandomAccessRange!R || is(typeof(lvalueOf!R[0] = lvalueOf!R.front)));
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;


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[]));


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


Boost License 1.0.