Unique

Undocumented in source.

Constructors

this
this(T value)
Undocumented in source.
this
this(typeof(this) rhs)
Undocumented in source.

Postblit

this(this)
this(this)
Undocumented in source.

Members

Functions

opAssign
void opAssign(T value)
Undocumented in source. Be warned that the author may not have intended to support it.
opAssign
void opAssign(typeof(null) n)
Undocumented in source. Be warned that the author may not have intended to support it.
release
void release(T dest)
Undocumented in source. Be warned that the author may not have intended to support it.
release
void release(typeof(this) dest)
Undocumented in source. Be warned that the author may not have intended to support it.
release
typeof(this) release()
Undocumented in source. Be warned that the author may not have intended to support it.
releaseRaw
T releaseRaw()
Undocumented in source. Be warned that the author may not have intended to support it.

Mixins

__anonymous
mixin accessFuncs!true
Undocumented in source.

Properties

isNull
bool isNull [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
ptrUnsafe
inout(T)* ptrUnsafe [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

1 int dtor = 0;
2 static struct S
3 {
4     int num;
5     int* dtor;
6     @disable this(this){}
7     @nogc nothrow ~this()
8     {
9         if(dtor)
10             (*dtor)++;
11     }
12 }
13 
14 S s = S(200, &dtor);
15 Unique!S a = s;
16 Unique!S b;
17 
18 assert(s == S.init);
19 assert(!a.isNull);
20 assert(b.isNull);
21 assert(a.ptrUnsafe.num == 200);
22 a.access((scope ref v)
23 {
24     assert(v.num == 200);
25     v.num *= 2;
26 });
27 
28 move(a, b);
29 assert(a.isNull);
30 assert(a._value == S.init);
31 assert(!b.isNull);
32 assert(b.ptrUnsafe.num == 400);
33 
34 a = Unique!S(S(800, &dtor));
35 assert(!a.isNull);
36 assert(a.ptrUnsafe.num == 800);
37 a = null;
38 assert(a.isNull);
39 assert(a._value == S.init);
40 assert(dtor == 1);
41 
42 b.release(s);
43 assert(b.isNull);
44 assert(s.num == 400);
45 
46 a = s;
47 a.release(b);
48 assert(a.isNull);
49 assert(!b.isNull);
50 
51 void test(Unique!S s)
52 {
53     assert(!s.isNull);
54     auto ss = s.releaseRaw();
55     assert(s.isNull);
56     assert(ss.num == 400);
57 }
58 
59 test(b.release);
60 assert(dtor == 2);
61 
62 Unique!S test2(Unique!S s)
63 {
64     assert(!s.isNull);
65     return s.release;
66 }
67 
68 a = S(200, &dtor);
69 b = test2(a.release);
70 assert(dtor == 2);
71 assert(a.isNull);
72 assert(!b.isNull);
73 b.__xdtor();
74 assert(dtor == 3);

Meta