moveToGC

Moves a value to a new GC allocation.

T*
moveToGC
(
T
)
(
auto ref T value
)

Parameters

value T

Value to be moved. If the argument is an lvalue and a struct with a destructor or postblit, it will be reset to its .init value.

Return Value

Type: T*

A pointer to the new GC-allocated value.

Examples

struct S
{
    int x;
    this(this) @disable;
    ~this() @safe pure nothrow @nogc {}
}

S* p;

// rvalue
p = moveToGC(S(123));
assert(p.x == 123);

// lvalue
auto lval = S(456);
p = moveToGC(lval);
assert(p.x == 456);
assert(lval.x == 0);

Meta