RcPtr.opAssign - multiple declarations
Function RcPtr.opAssign
Releases the ownership of the managed object, if any.
void opAssign(MemoryOrder order = MemoryOrder .seq, This)
(
typeof(null) nil
) scope
if (isMutable!This);
After the call, this manages no object.
Examples
{
RcPtr!long x = RcPtr!long .make(1);
assert(x .useCount == 1);
x = null;
assert(x .useCount == 0);
assert(x == null);
}
{
RcPtr!(shared long) x = RcPtr!(shared long) .make(1);
assert(x .useCount == 1);
x = null;
assert(x .useCount == 0);
assert(x == null);
}
{
shared RcPtr!(long) x = RcPtr!(shared long) .make(1);
assert(x .useCount == 1);
x = null;
assert(x .useCount == 0);
assert(x == null);
}
Function RcPtr.opAssign
Shares ownership of the object managed by rhs
.
void opAssign(MemoryOrder order = MemoryOrder .seq, Rhs, This)
(
auto scope ref Rhs desired
) scope
if (isRcPtr!Rhs && !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
{
RcPtr!long px1 = RcPtr!long .make(1);
RcPtr!long px2 = RcPtr!long .make(2);
assert(px2 .useCount == 1);
px1 = px2;
assert(*px1 == 2);
assert(px2 .useCount == 2);
}
{
RcPtr!long px = RcPtr!long .make(1);
RcPtr!(const long) pcx = RcPtr!long .make(2);
assert(px .useCount == 1);
pcx = px;
assert(*pcx == 1);
assert(pcx .useCount == 2);
}
{
const RcPtr!long cpx = RcPtr!long .make(1);
RcPtr!(const long) pcx = RcPtr!long .make(2);
assert(pcx .useCount == 1);
pcx = cpx;
assert(*pcx == 1);
assert(pcx .useCount == 2);
}
{
RcPtr!(immutable long) pix = RcPtr!(immutable long) .make(123);
RcPtr!(const long) pcx = RcPtr!long .make(2);
assert(pix .useCount == 1);
pcx = pix;
assert(*pcx == 123);
assert(pcx .useCount == 2);
}