The OpenD Programming Language

createSlimRC

template createSlimRC(T)
createSlimRC
(
Args...
)
(
auto ref Args args
)
if (
!is(T == interface) &&
!__traits(isAbstractClass, T)
)

Members

Functions

createSlimRC
mir_slim_rcptr!T createSlimRC(Args args)

Examples

auto a = createSlimRC!double(10);
auto b = a;
assert(*b == 10);
*b = 100;
assert(*a == 100);

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);

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);

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);

Meta