SharedPtr.lock

Creates a new non weak SharedPtr that shares ownership of the managed object (must be SharedPtr.WeakType).

If there is no managed object, i.e. this is empty or this is expired, then the returned SharedPtr is empty. Method exists only if SharedPtr is isWeak

struct SharedPtr
scope
lock
()
()
if (
isCopyConstructable!(typeof(this), SharedType)
)

Examples

{
	SharedPtr!long x = SharedPtr!long.make(123);

	auto w = x.weak;    //weak ptr

	SharedPtr!long y = w.lock;

	assert(x == y);
	assert(x.useCount == 2);
	assert(y.get == 123);
}

{
	SharedPtr!long x = SharedPtr!long.make(123);

	auto w = x.weak;    //weak ptr

	assert(w.expired == false);

	x = SharedPtr!long.make(321);

	assert(w.expired == true);

	SharedPtr!long y = w.lock;

	assert(y == null);
}

Meta