move

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. target is destroyed before the new value is assigned. If target isn't initialized and therefore shouldn't be destroyed, $(D_PSYMBOL moveEmplace) can be used.

If target isn't specified, $(D_PSYMBOL move) returns the source as rvalue without calling its copy constructor or destructor.

source and target are the same object, $(D_PSYMBOL move) does nothing.

  1. void move(T source, T target)
    void
    move
    (
    T
    )
    (
    ref T source
    ,
    ref T target
    )
  2. T move(T source)

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;
move(source, target);
assert(target.member == 5);
assert(move(target).member == 5);

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

See Also

$(D_PSYMBOL moveEmplace).

Meta