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 hasMobileElements
Returns true
iff R
is an input range that supports the
primitive, as well as moveFront
and moveBack
if it's a
bidirectional or random access range. These may be explicitly implemented, or
may work via the default behavior of the module level functions moveAt
and friends. The following code should compile for any range
with mobile elements.
moveFront
alias E = ElementType!R; R r; static assert(isInputRange!R); static assert(is(typeof(moveFront(r)) == E)); static if (isBidirectionalRange!R) static assert(is(typeof(moveBack(r)) == E)); static if (isRandomAccessRange!R) static assert(is(typeof(moveAt(r, 0)) == E));
Declaration
enum hasMobileElements(R) = isInputRange!R && is(typeof((inout int = 0) { alias E = ElementType!R; R r = R.init; static assert(is(typeof(moveFront(r)) == E)); static if (isBidirectionalRange!R) { static assert(is(typeof(moveBack(r)) == E)); } static if (isRandomAccessRange!R) { static assert(is(typeof(moveAt(r, 0)) == E)); } } ));
Example
import std.algorithm : map; import std.range : iota, repeat; static struct HasPostblit { this(this) {} } auto nonMobile = map!"a"(repeat(HasPostblit.init)); static assert(!hasMobileElements!(typeof(nonMobile))); static assert( hasMobileElements!(int[])); static assert( hasMobileElements!(inout(int)[])); static assert( hasMobileElements!(typeof(iota(1000)))); static assert( hasMobileElements!( string)); static assert( hasMobileElements!(dstring)); static assert( hasMobileElements!( char[])); static assert( hasMobileElements!(dchar[]));
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.