Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

mir.rc.slim_ptr

Thread-safe slim reference-counted shared pointers

.
This implementation does not support polymorphism.
struct mir_slim_rcptr(T);
Thread safe reference counting array.
This implementation does not support polymorphism.
The implementation never adds roots into the GC.
Unqual!T _value;

template opUnary(string op : "*")
inout @property scope inout(T) _get_value();
pure nothrow @nogc @safe void proxySwap(ref typeof(this) rhs);
this(typeof(null));
const pure nothrow @nogc scope @safe bool opEquals(typeof(null));

const pure nothrow @nogc scope @safe bool opEquals(Y)(auto ref scope const ThisTemplate!Y rhs);
const pure nothrow @nogc scope @trusted auto opCmp(Y)(auto ref scope const ThisTemplate!Y rhs);
const pure nothrow @nogc scope @trusted size_t toHash();
ref @trusted auto opAssign(typeof(null)) return;
ref @trusted auto opAssign(return typeof(this) rhs) return;
ref @trusted auto opAssign(Q)(return ThisTemplate!Q rhs) return
if (isImplicitlyConvertible!(Q*, T*));
alias SlimRCPtr = mir_slim_rcptr(T);
template createSlimRC(T) if (!is(T == interface) && !__traits(isAbstractClass, T))
Examples:
auto a = createSlimRC!double(10);
auto b = a;
assert(*b == 10);
*b = 100;
assert(*a == 100);
Examples:
Classes
static class C
{
    int index;
    double value;
    ref double bar() @safe pure nothrow @nogc { return value; }
    this(double d) { value = d; }

    override size_t toHash() const scope @safe pure nothrow @nogc
    {
        return index;
    }
}
auto a = createSlimRC!C(10);
assert(a._counter == 1);
auto b = a;
assert(a._counter == 2);
assert((*b).value == 10);
b.value = 100; // access via alias this syntax
assert(a.value == 100);
assert(a._counter == 2);
Examples:
Structs
struct S
{
    double e;
}
struct C
{
    int i;
    S s;
    // 'alias' should be accesable by reference
    // or a class/interface
    alias s this;
}

auto a = createSlimRC!C(10, S(3));
auto s = a;
assert(s._counter == 2);
assert(s.e == 3);
Examples:
Classes with empty constructor
static class C
{
    int index = 34;

    override size_t toHash() const scope @safe pure nothrow @nogc
    {
        return index;
    }
}
assert(createSlimRC!C.index == 34);
mir_slim_rcptr!T createSlimRC(Args...)(auto ref Args args);