Function RcPtr.ptr
Get pointer to managed object of ElementType
or reference if ElementType
is reference type (class or interface) or pointer to first dynamic array element.
ElementPointerTypeImpl!(GetElementType!This) ptr(This)() pure nothrow @nogc @property @system
if (!is(This == shared));
If this
is weak expired pointer then return null.
Doesn't increment useCount, is inherently unsafe.
Examples
{
RcPtr!long x = RcPtr!long .make(123);
assert(*x .ptr == 123);
x .get = 321;
assert(*x .ptr == 321);
const y = x;
assert(*y .ptr == 321);
assert(*x .ptr == 321);
static assert(is(typeof(y .ptr) == const(long)*));
}
{
auto x = RcPtr!(long[]) .make(6, 42);
assert(*x .ptr == 42);
static assert(is(typeof(x .ptr) == long*));
}
{
auto s = RcPtr!long .make(42);
const w = s .weak;
assert(*w .ptr == 42);
s = null;
assert(w .ptr is null);
}
{
auto s = RcPtr!long .make(42);
auto w = s .weak;
scope const p = w .ptr;
s = null;
assert(w .ptr is null);
assert(p !is null); //p is dangling pointer!
}