IntrusivePtr.store

Stores the non shared IntrusivePtr parameter ptr to this.

If this is shared then operation is atomic or guarded by mutex.

Template parameter order has type core.atomic.MemoryOrder.

struct IntrusivePtr
alias store = opAssign

Examples

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

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

//null store:
{
    shared x = IntrusivePtr!(shared Foo).make(123);
    assert(x.load.get.i == 123);

    x.store(null);
    assert(x.useCount == 0);
    assert(x.load == null);
}

//rvalue store:
{
    shared x = IntrusivePtr!(shared Foo).make(123);
    assert(x.load.get.i == 123);

    x.store(IntrusivePtr!(shared Foo).make(42));
    assert(x.load.get.i == 42);
}

//lvalue store:
{
    shared x = IntrusivePtr!(shared Foo).make(123);
    auto y = IntrusivePtr!(shared Foo).make(42);

    assert(x.load.get.i == 123);
    assert(y.load.get.i == 42);

    x.store(y);
    assert(x.load.get.i == 42);
    assert(x.useCount == 2);
}

Meta