Function share

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

shared(Ptr) share(Ptr) (
  auto scope ref Ptr ptr
)
if (isSharedPtr!Ptr);

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

Example

{
	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);

}