Function IntrusivePtr.make
Constructs an object of type ElementType
and wraps it in a IntrusivePtr
using args as the parameter list for the constructor of ElementType
.
IntrusivePtr!ElementType make(AllocatorType, bool supportGC = platformSupportGC, Args...)
(
auto ref Args args
);
The object is constructed as if by the expression emplace!ElementType(_payload, forward!args)
, where payload is an internal pointer to storage suitable to hold an object of type ElementType
.
The storage is typically larger than ElementType
in order to use one allocation for both the control block and the ElementType
object.
Examples
static struct Foo{
ControlBlock!(int, int) c;
int i;
this(int i)pure nothrow @safe @nogc{
this .i = i;
}
}
{
IntrusivePtr!Foo a = IntrusivePtr!Foo .make();
assert(a .get .i == 0);
IntrusivePtr!(const Foo) b = IntrusivePtr!Foo .make(2);
assert(b .get .i == 2);
}
{
static struct Struct{
ControlBlock!int c;
int i = 7;
this(int i)pure nothrow @safe @nogc{
this .i = i;
}
}
IntrusivePtr!Struct s1 = IntrusivePtr!Struct .make();
assert(s1 .get .i == 7);
IntrusivePtr!Struct s2 = IntrusivePtr!Struct .make(123);
assert(s2 .get .i == 123);
}