Function share

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

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

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

Example

{
    auto x = RcPtr!(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 = RcPtr!(long).make(123);
    assert(x.useCount == 1);

    ///error `shared RcPtr` need shared `ControlType` and shared `ElementType`.
    //shared s1 = share(x);

}