IntrusivePtr.this - multiple declarations
Function IntrusivePtr.this
Forward constructor (merge move and copy constructor).
this(Rhs, This)
(
auto scope ref Rhs rhs,
Forward
) @trusted
if (isIntrusivePtr!Rhs && !is(Rhs == shared));
Function IntrusivePtr.this
Constructs a IntrusivePtr
without managed object. Same as IntrusivePtr
this(This)
(
typeof(null) nil
) pure nothrow @nogc @safe;
Examples
static struct Foo{
ControlBlock!(int, int) c;
}
{
IntrusivePtr!Foo x = null;
assert(x == null);
assert(x == IntrusivePtr!Foo .init);
}
Function IntrusivePtr.this
Constructs a IntrusivePtr
which shares ownership of the object managed by rhs
.
this(Rhs, This)
(
auto scope ref Rhs rhs
) @trusted
if (isIntrusivePtr!Rhs && !is(Rhs == shared) && !isMoveCtor!(This, rhs));
If rhs manages no object, this manages no object too.
If rhs if rvalue then ownership is moved.
The template overload doesn't participate in overload resolution if ElementType of typeof(rhs)
is not implicitly convertible to ElementType
.
If rhs if WeakType
then this ctor is equivalent to this(rhs
.
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(123);
assert(x .useCount == 1);
IntrusivePtr!Foo a = x; //lvalue copy ctor
assert(a == x);
const IntrusivePtr!Foo b = x; //lvalue copy ctor
assert(b == x);
IntrusivePtr!Foo c = x; //lvalue ctor
assert(c == x);
//const IntrusivePtr!Foo d = b; //lvalue ctor
//assert(d == x);
assert(x .useCount == 4);
}
{
import core .lifetime : move;
IntrusivePtr!Foo x = IntrusivePtr!Foo .make(123);
assert(x .useCount == 1);
IntrusivePtr!Foo a = move(x); //rvalue copy ctor
assert(a .useCount == 1);
const IntrusivePtr!Foo b = move(a); //rvalue copy ctor
assert(b .useCount == 1);
IntrusivePtr!(const Foo) c = b .load; //rvalue ctor
assert(c .useCount == 2);
const IntrusivePtr!Foo d = move(c); //rvalue ctor
assert(d .useCount == 2);
}