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; } } 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; } assert(createSlimRC!C.index == 34);