View source code
Display the source code in std/algorithm/mutation.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.
Function std.algorithm.mutation.swapRanges
Swaps all elements of
with successive elements in r1
.
Returns a tuple containing the remainder portions of r2
and r1
that were not swapped (one of them will be empty). The ranges may
be of different types but must have the same element type and support
swapping.
r2
Prototype
Tuple!(Range1,Range2) swapRanges(Range1, Range2)( Range1 r1, Range2 r2 ) if (isInputRange!Range1 && isInputRange!Range2 && hasSwappableElements!Range1 && hasSwappableElements!Range2 && is(ElementType!Range1 == ElementType!Range2));
Example
int[] a = [ 100, 101, 102, 103 ]; int[] b = [ 0, 1, 2, 3 ]; auto c = swapRanges(a[1 .. 3], b[2 .. 4]); assert(c[0].empty && c[1].empty); assert(a == [ 100, 2, 3, 103 ]); assert(b == [ 0, 1, 101, 102 ]); } /** Initializes each element ofrange
withvalue
. Assumes that the elements of the range are uninitialized. This is of interest for structs that define copy constructors (for all other types, fill and uninitializedFill are equivalent). Params: range = An input _range that exposes references to its elements and has assignable elements value = Assigned to each element of range See_Also: fill initializeAll Example:
struct S { ...