GlobalPtr.opAssign - multiple declarations

Function GlobalPtr.opAssign

Assign.

void opAssign (
  typeof(null) nil
) pure nothrow @nogc scope @trusted;

void opAssign (
  typeof(null) nil
) shared pure nothrow @nogc scope @trusted;

void opAssign (
  GlobalPtr.ElementReferenceType elm
) pure nothrow @nogc scope @trusted;

Examples

{
    GlobalPtr!long x = new long(1);

    x = null;
    assert(x == null);
}

{
    GlobalPtr!(shared long) x = new shared(long)(1);

    x = null;
    assert(x == null);
}

{
    shared GlobalPtr!(long) x = new shared(long)(1);

    x = null;
    assert(x == null);
}

Function GlobalPtr.opAssign

Shares ownership of the object managed by rhs.

void opAssign(Rhs, This) (
  auto scope ref Rhs desired
) scope @trusted
if (isGlobalPtr!Rhs && isAssignable!(Rhs, This) && !is(Rhs == shared));

If rhs manages no object, this manages no object too. If rhs is rvalue then move-assigns a RcPtr from rhs

Examples

{
    GlobalPtr!long px1 = new long(1);
    GlobalPtr!long px2 = new long(2);

    px1 = px2;
    assert(*px1 == 2);
}


{
    GlobalPtr!long px = new long(1);
    GlobalPtr!(const long) pcx = new long(2);

    pcx = px;
    assert(*pcx == 1);
}


{
    const GlobalPtr!long cpx = new long(1);
    GlobalPtr!(const long) pcx = new long(2);

    pcx = cpx;
    assert(*pcx == 1);
}

{
    GlobalPtr!(immutable long) pix = new immutable(long)(123);
    GlobalPtr!(const long) pcx = new long(2);

    pcx = pix;
    assert(*pcx == 123);
}