IntrusivePtr.opAssign - multiple declarations
Function IntrusivePtr.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
static struct Foo{
ControlBlock!(int, int) c;
int i;
this(int i)pure nothrow @safe @nogc{
this .i = i;
}
}
{
IntrusivePtr!Foo x = IntrusivePtr!Foo .make(1);
assert(x .useCount == 1);
x = null;
assert(x .useCount == 0);
assert(x == null);
}
{
IntrusivePtr!(shared Foo) x = IntrusivePtr!(shared Foo) .make(1);
assert(x .useCount == 1);
x = null;
assert(x .useCount == 0);
assert(x == null);
}
{
shared IntrusivePtr!(shared Foo) x = IntrusivePtr!(shared Foo) .make(1);
assert(x .useCount == 1);
x = null;
assert(x .useCount == 0);
assert(x .load == null);
}
Function IntrusivePtr.opAssign
Shares ownership of the object managed by rhs
.
void opAssign(MemoryOrder order = MemoryOrder .seq, Rhs, This)
(
auto scope ref Rhs desired
) scope
if (isIntrusivePtr!Rhs && !is(Rhs == shared));
If rhs
manages no object, this
manages no object too.
If rhs
is rvalue then move-assigns a IntrusivePtr
from rhs
Examples
static struct Foo{
ControlBlock!(int, int) c;
int i;
this(int i)pure nothrow @safe @nogc{
this .i = i;
}
}
{
IntrusivePtr!Foo px1 = IntrusivePtr!Foo .make(1);
IntrusivePtr!Foo px2 = IntrusivePtr!Foo .make(2);
assert(px2 .useCount == 1);
px1 = px2;
assert(px1 .get .i == 2);
assert(px2 .useCount == 2);
}
{
IntrusivePtr!(Foo) px = IntrusivePtr!(Foo) .make(1);
IntrusivePtr!(const Foo) pcx = IntrusivePtr!(Foo) .make(2);
assert(px .useCount == 1);
pcx = px;
assert(pcx .get .i == 1);
assert(pcx .useCount == 2);
}