Array.opAssign

Assign rhs to this array. The current array will now become another reference to rhs, unless rhs is null, in which case the current array will become empty. If rhs refers to the current array nothing will happen.

If there are no more references to the previous array, the previous array will be destroyed; this leads to a O(n) complexity.

struct Array(T)
ref
opAssign
()
(
auto ref typeof(this) rhs
)

Parameters

rhs typeof(this)

a reference to an array

Return Value

Type: auto ref

a reference to this array

Complexity: O(n).

Examples

import std.algorithm.comparison : equal;

auto a = Array!int(1);
auto a2 = Array!int(1, 2);

a = a2; // this will free the old a
assert(equal(a, [1, 2]));
a.front = 0;
assert(equal(a2, [0, 2]));

Meta