swapRanges

Swaps all elements of r1 with successive elements in r2. Returns a tuple containing the remainder portions of r1 and r2 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.

Tuple!(InputRange1, InputRange2)
swapRanges
(
InputRange1
InputRange2
)
(
InputRange1 r1
,
InputRange2 r2
)
if (
hasSwappableElements!InputRange1 &&
&&
is(ElementType!InputRange1 == ElementType!InputRange2)
)

Parameters

r1 InputRange1

an input range with swappable elements

r2 InputRange2

an input range with swappable elements

Return Value

Type: Tuple!(InputRange1, InputRange2)

Tuple containing the remainder portions of r1 and r2 that were not swapped

Examples

import std.range : empty;
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 ]);

Meta