reset

Utility that resets value state in a way that its memory can be reused again as much as possible. Resets arrays to 0 length and values to their init state.

Non-class references are ignored. For classes it tries to recurse into fields of the class instance without nullifying actual reference.

void
reset
(
T
)
(
ref T value
)

Parameters

value T

value to reset

Examples

// Can reset single value:
int x = 42;
reset(x);
test!("==")(x, 0);

// Or some array:
int[] arr = [ 1, 2, 3 ];
reset(arr);
test!("==")(arr.length, 0);
test!("!=")(arr.ptr, null);

// Or some aggregate recursively:
struct S
{
    int x;
    mstring buf;
}

auto s = S(42, "abcd".dup);
reset(s);
test!("==")(s.x, 0);
test!("==")(s.buf.length, 0);

Meta