Function first
Return SharedPtr
pointing to first element of array managed by shared pointer ptr
.
auto first(Ptr)
(
auto scope ref Ptr ptr
) @trusted
if (isSharedPtr!Ptr && !is(Ptr == shared) && is(Ptr .ElementType : T[], T));
Example
//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);
}