IntrusivePtr.opAssign

Shares ownership of the object managed by rhs.

If rhs manages no object, this manages no object too. If rhs is rvalue then move-assigns a IntrusivePtr from rhs

  1. void opAssign(typeof(null) nil)
  2. void opAssign(Rhs desired)
    struct IntrusivePtr
    scope
    void
    opAssign
    (
    MemoryOrder order = MemoryOrder.seq
    Rhs
    this This
    )
    (
    scope auto ref Rhs desired
    )
    if (
    !is(Rhs == shared)
    )

Examples

static struct Foo{
    ControlBlock!(int, int) c;
    int i;

    this(int i)pure nothrow @safe @nogc{
        this.i = i;
    }
}

{
    IntrusivePtr!Foo px1 = IntrusivePtr!Foo.make(1);
    IntrusivePtr!Foo px2 = IntrusivePtr!Foo.make(2);

    assert(px2.useCount == 1);
    px1 = px2;
    assert(px1.get.i == 2);
    assert(px2.useCount == 2);
}


{
    IntrusivePtr!(Foo) px = IntrusivePtr!(Foo).make(1);
    IntrusivePtr!(const Foo) pcx = IntrusivePtr!(Foo).make(2);

    assert(px.useCount == 1);
    pcx = px;
    assert(pcx.get.i == 1);
    assert(pcx.useCount == 2);
}

Meta