share

Return shared SharedPtr pointing to same managed object like parameter ptr.

Type of parameter ptr must be SharedPtr with shared(ControlType) and shared/immutable ElementType .

shared(Ptr)
share
(
Ptr
)
(
scope auto ref Ptr ptr
)

Examples

{
	auto x = SharedPtr!(shared long).make(123);
	assert(x.useCount == 1);

	shared s1 = share(x);
	assert(x.useCount == 2);


	import core.lifetime : move;
	shared s2 = share(x.move);
	assert(x == null);
	assert(s2.useCount == 2);
	assert(s2.load.get == 123);

}

{
	auto x = SharedPtr!(long).make(123);
	assert(x.useCount == 1);

	///error `shared SharedPtr` need shared `ControlType` and shared `ElementType`.
	//shared s1 = share(x);

}

Meta