RcPtr.this - multiple declarations

Function RcPtr.this

Forward constructor (merge move and copy constructor).

this(Rhs, This) (
  auto scope ref Rhs rhs,
  Forward
) @trusted
if (isRcPtr!Rhs && !is(Rhs == shared));

Function RcPtr.this

Constructs a RcPtr without managed object. Same as RcPtr.init

this(This) (
  typeof(null) nil
) pure nothrow @nogc @safe;

Examples

RcPtr!long x = null;

assert(x == null);
assert(x == RcPtr!long.init);

Function RcPtr.this

Constructs a RcPtr which shares ownership of the object managed by rhs.

this(Rhs, This) (
  auto scope ref Rhs rhs
) @trusted
if (isRcPtr!Rhs && !is(Rhs == shared) && !isMoveCtor!(This, rhs));

If rhs manages no object, this manages no object too. If rhs if rvalue then ownership is moved. The template overload doesn't participate in overload resolution if ElementType of typeof(rhs) is not implicitly convertible to ElementType. If rhs if WeakType then this ctor is equivalent to this(rhs.lock()).

Examples

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

    RcPtr!long a = x;         //lvalue copy ctor
    assert(a == x);

    const RcPtr!long b = x;   //lvalue copy ctor
    assert(b == x);

    RcPtr!(const long) c = x; //lvalue ctor
    assert(c == x);

    const RcPtr!long d = b;   //lvalue ctor
    assert(d == x);

    assert(x.useCount == 5);
}

{
    import core.lifetime : move;
    RcPtr!long x = RcPtr!long.make(123);
    assert(x.useCount == 1);

    RcPtr!long a = move(x);        //rvalue copy ctor
    assert(a.useCount == 1);

    const RcPtr!long b = move(a);  //rvalue copy ctor
    assert(b.useCount == 1);

    RcPtr!(const long) c = b.load;  //rvalue ctor
    assert(c.useCount == 2);

    const RcPtr!long d = move(c);  //rvalue ctor
    assert(d.useCount == 2);
}

{
    import core.lifetime : move;
    auto u = UniquePtr!(long, SharedControlBlock).make(123);

    RcPtr!long s = move(u);        //rvalue copy ctor
    assert(s != null);
    assert(s.useCount == 1);

    RcPtr!long s2 = UniquePtr!(long, SharedControlBlock).init;
    assert(s2 == null);
}