first

Return SharedPtr pointing to first element of array managed by shared pointer ptr.

@trusted
first
(
Ptr
)
(
scope auto ref Ptr ptr
)
if (
isSharedPtr!Ptr &&
!is(Ptr == shared)
&&
is(Ptr.ElementType : T[],
T
)
)

Examples

//copy
{
	auto x = SharedPtr!(long[]).make(10, -1);
	assert(x.length == 10);

	auto y = first(x);
	static assert(is(typeof(y) == SharedPtr!long));
	assert(*y == -1);
	assert(x.useCount == 2);
}

{
	auto x = SharedPtr!(long[10]).make(-1);
	assert(x.get.length == 10);

	auto y = first(x);
	static assert(is(typeof(y) == SharedPtr!long));
	assert(*y == -1);
	assert(x.useCount == 2);
}

//move
import core.lifetime : move;
{
	auto x = SharedPtr!(long[]).make(10, -1);
	assert(x.length == 10);

	auto y = first(x.move);
	static assert(is(typeof(y) == SharedPtr!long));
	assert(*y == -1);
}

{
	auto x = SharedPtr!(long[10]).make(-1);
	assert(x.get.length == 10);

	auto y = first(x.move);
	static assert(is(typeof(y) == SharedPtr!long));
	assert(*y == -1);
}

Meta