Function IntrusivePtr.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

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.element.i == 123);

    x.get.i = 321;
    assert(x.element.i == 321);

    const y = x;
    assert(y.element.i == 321);
    assert(x.element.i == 321);

    static assert(is(typeof(y.element) == const(Foo)*));
}

{
    auto s = IntrusivePtr!Foo.make(42);
    const w = s.weak;

    assert(w.element.i == 42);

    s = null;
    assert(w.element is null);
}

{
    auto s = IntrusivePtr!Foo.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!
}