IntrusivePtr.this

Constructs a IntrusivePtr which shares ownership of the object managed by rhs.

If rhs manages no object, this manages no object too. If rhs if rvalue then ownership is moved. The template overload doesn't participate in overload resolution if ElementType of typeof(rhs) is not implicitly convertible to ElementType. If rhs if WeakType then this ctor is equivalent to this(rhs.lock()).

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.useCount == 1);

    IntrusivePtr!Foo a = x;         //lvalue copy ctor
    assert(a == x);

    const IntrusivePtr!Foo b = x;   //lvalue copy ctor
    assert(b == x);

    IntrusivePtr!Foo c = x; //lvalue ctor
    assert(c == x);

    //const IntrusivePtr!Foo d = b;   //lvalue ctor
    //assert(d == x);

    assert(x.useCount == 4);
}

{
    import core.lifetime : move;
    IntrusivePtr!Foo x = IntrusivePtr!Foo.make(123);
    assert(x.useCount == 1);

    IntrusivePtr!Foo a = move(x);        //rvalue copy ctor
    assert(a.useCount == 1);

    const IntrusivePtr!Foo b = move(a);  //rvalue copy ctor
    assert(b.useCount == 1);

    IntrusivePtr!(const Foo) c = b.load;  //rvalue ctor
    assert(c.useCount == 2);

    const IntrusivePtr!Foo d = move(c);  //rvalue ctor
    assert(d.useCount == 2);
}

Meta