Function RcPtr.element
Get pointer to managed object of ElementType
or reference if ElementType
is reference type (class or interface) or dynamic array.
ElementReferenceTypeImpl!(GetElementType!This) element(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 .element == 123);
x .get = 321;
assert(*x .element == 321);
const y = x;
assert(*y .element == 321);
assert(*x .element == 321);
static assert(is(typeof(y .element) == const(long)*));
}
{
auto x = RcPtr!(long[]) .make(6, 42);
assert(x .element[0] == 42);
static assert(is(typeof(x .element) == long[]));
}
{
auto s = RcPtr!long .make(42);
const w = s .weak;
assert(*w .element == 42);
s = null;
assert(w .element is null);
}
{
auto s = RcPtr!long .make(42);
auto w = s .weak;
scope const p = w .element;
s = null;
assert(w .element is null);
assert(p !is null); //p is dangling pointer!
}