SharedPtr.store

Stores the non shared SharedPtr 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 SharedPtr
alias store = opAssign

Examples

//null store:
{
	shared x = SharedPtr!(shared long).make(123);
	assert(x.load.get == 123);

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

//rvalue store:
{
	shared x = SharedPtr!(shared long).make(123);
	assert(x.load.get == 123);

	x.store(SharedPtr!(shared long).make(42));
	assert(x.load.get == 42);
}

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

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

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

Meta