Function intrusivePtr
Create IntrusivePtr
instance from class reference Elm
or struct pointer element Elm
.
auto intrusivePtr(Elm)
(
Elm elm
)
if (is(Elm == class) && isIntrusive!Elm);
auto intrusivePtr(Ptr, Elm)
(
Ptr elm
)
if (is(Elm == struct) && isIntrusive!Elm);
Elm
was created by IntrusivePtr
or IntrusivePtr
.
Example
static class Foo{
private ControlBlock!int control;
int i;
this(int i)pure nothrow @safe @nogc{
this .i = i;
}
}
static struct Bar{
private ControlBlock!int control;
int i;
this(int i)pure nothrow @safe @nogc{
this .i = i;
}
}
{
auto i = IntrusivePtr!Foo .make(42);
assert(i .useCount == 1);
Foo foo = i .get;
auto i2 = intrusivePtr(foo);
assert(i .useCount == 2);
}
{
auto i = IntrusivePtr!Bar .make(42);
assert(i .useCount == 1);
Bar* bar = i .element;
auto i2 = intrusivePtr(bar);
assert(i .useCount == 2);
}