var.idup

var idup() const @safe

Create an independent deep copy of this var under an idup-style name.

This method is functionally equivalent to dup(): it returns a regular mutable var whose nested containers and native buffers are freshly allocated and independent of the original. Mutating the returned value never affects the source.

Note

the return type is deliberately mutable var. It does not

convert to immutable(var) implicitly (D immutability is transitive over the nested mutable containers), so the return value cannot be published as an immutable snapshot without an explicit cast; no such freeze API is currently provided.

Returns

A new mutable var that is a deep copy of this value.

Examples

var original = var([1, 2, 3]);
var copy = original.idup;
copy[0] = 99;
assert(original[0].as!int == 1); // independent nested copy