moveEmplace

Moves source into target assuming that target isn't initialized.

Moving the source copies it into the target and places the source into a valid but unspecified state, which means that after moving source can be destroyed or assigned a new value, but accessing it yields an unspecified value. No postblits or destructors are called. If the target should be destroyed before, use $(D_PSYMBOL move).

source and target must be different objects.

@system
void
moveEmplace
(
T
)
(
ref T source
,
ref T target
)

Parameters

T

Object type.

source T

Source object.

target T

Target object.

Examples

static struct S
{
    int member = 5;

    this(this) @nogc nothrow pure @safe
    {
        assert(false);
    }
}
S source, target = void;
moveEmplace(source, target);
assert(target.member == 5);

int x1 = 5, x2;
moveEmplace(x1, x2);
assert(x2 == 5);

See Also

$(D_PSYMBOL move), $(D_PSYMBOL hasElaborateCopyConstructor), $(D_PSYMBOL hasElaborateDestructor).

Precondition: &source !is &target.

Meta