GlobalPtr.opAssign

Shares ownership of the object managed by rhs.

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

  1. void opAssign(typeof(null) nil)
  2. void opAssign(typeof(null) nil)
  3. void opAssign(ElementReferenceType elm)
  4. void opAssign(Rhs desired)
    struct GlobalPtr
    scope @trusted
    void
    opAssign
    (
    Rhs
    this This
    )
    (
    scope auto ref Rhs desired
    )
    if (
    isGlobalPtr!Rhs &&
    isAssignable!(Rhs, This)
    &&
    !is(Rhs == shared)
    )

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);
}

Meta