Vector.heapSwap

Swaps the contents of this and rhs only if both are heap allocated.

Return true if swap successed or false if not (this or rhs is non heap allocated).

struct Vector
scope
bool
heapSwap
()
(
ref scope typeof(this) rhs
)

Examples

auto a = Vector!(int, 3).build(1, 2, 3);
auto b = Vector!(int, 3).build(6, 7, 8);

assert(a.heapSwap(b) == false);
assert(a == [1, 2, 3]);
assert(b == [6, 7, 8]);

a ~= 4;
b ~= 9;
assert(a == [1, 2, 3, 4]);
assert(b == [6, 7, 8, 9]);

assert(a.heapSwap(b) == true);
assert(a == [6, 7, 8, 9]);
assert(b == [1, 2, 3, 4]);

Meta