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.hasSwappableElements
Returns true
if R
is an input range and has swappable
elements. The following code should compile for any range
with swappable elements.
enum hasSwappableElements(R)
= isInputRange!R && is(typeof((ref R r) => swap(r .front, r .front))) && (!isBidirectionalRange!R || is(typeof((ref R r) => swap(r .back, r .front)))) && (!isRandomAccessRange!R || is(typeof((ref R r) => swap(r[0], r .front))));
R r;
static assert(isInputRange!R);
swap(r .front, r .front);
static if (isBidirectionalRange!R) swap(r .back, r .front);
static if (isRandomAccessRange!R) swap(r[0], r .front);
Example
static assert(!hasSwappableElements!(const int[]));
static assert(!hasSwappableElements!(const(int)[]));
static assert(!hasSwappableElements!(inout(int)[]));
static assert( hasSwappableElements!(int[]));
static assert(!hasSwappableElements!( string));
static assert(!hasSwappableElements!(dstring));
static assert(!hasSwappableElements!( char[]));
static assert( hasSwappableElements!(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
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.