first

Return RcPtr pointing to first element of dynamic array managed by rc pointer ptr.

  1. auto first(Ptr ptr)
    @trusted
    first
    (
    Ptr
    )
    (
    scope ref Ptr ptr
    )
    if (
    isRcPtr!Ptr &&
    is(Ptr.ElementType : T[],
    T
    )
    )
  2. auto first(Ptr ptr)

Examples

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

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

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

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

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

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

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

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

Meta