A destructor is present on this object, but not explicitly documented in the source.
A postblit is present on this object, but not explicitly documented in the source.
Allowed types list
_is overload that accept .Algebraic.Kind.
get overload that accept .Algebraic.Kind.
trustedGet overload that accept .Algebraic.Kind.
Algebraic Kind.
Checks if the underlaying type is an element of a user provided type set.
Checks if the storage stores an allowed type.
Defined if the first type is typeof(null)
Gets the value if not null. If this is in the null state, and the optional parameter fallback was provided, it will be returned. Without fallback, calling get with a null state is invalid.
Gets an algebraic subset.
Defined if the first type is typeof(null)
Determines if the variant holds value of some none-isVariant type. The property is avaliable only for
Defined if the first type is typeof(null)
Requires mir-algorithm package
nothrow .Algebraic.get alternative that returns an algebraic subset.
Zero cost always nothrow get alternative
Gets the value if not null. If this is in the null state, and the optional parameter fallback was provided, it will be returned. Without fallback, calling get with a null state is invalid.
Defined if AllowedTypes contains void
Gets an algebraic subset.
nothrow .Algebraic.get alternative that returns an algebraic subset.
Constructor and methods propagation.
1 static struct Base 2 { 3 double d; 4 } 5 6 static class Cc 7 { 8 // alias this members are supported 9 Base base; 10 alias base this; 11 12 int a; 13 private string _b; 14 15 @safe pure nothrow @nogc: 16 17 override size_t toHash() scope const { return hashOf(_b) ^ a; } 18 19 string b() const @property { return _b; } 20 void b(string b) @property { _b = b; } 21 22 int retArg(int v) { return v; } 23 string retArgT(TArgs...)(int v) { return TArgs.stringof; } 24 25 this(int a, string b) 26 { 27 this.a = a; 28 this._b = b; 29 } 30 } 31 32 static struct S 33 { 34 string b; 35 int a; 36 37 double retArg(double v) { return v; } 38 double retArgT(TArgs...)(int v) { return v * TArgs.length; } 39 40 // alias this members are supported 41 Base base; 42 alias base this; 43 } 44 45 static void inc(ref int a) { a++; } 46 47 alias V = Nullable!(Cc, S); // or Variant! 48 49 auto v = V(2, "str"); 50 assert(v._is!Cc); 51 assert(v.a == 2); 52 assert(v.b == "str"); 53 // members are returned by reference if possible 54 inc(v.a); 55 assert(v.a == 3); 56 v.b = "s"; 57 assert(v.b == "s"); 58 // alias this members are supported 59 v.d = 10; 60 assert(v.d == 10); 61 // method call support 62 assert(v.retArg(100)._is!int); 63 assert(v.retArg(100) == 100); 64 65 // method with template args support 66 assert(v.retArgT!dchar(100)._is!string); 67 assert(v.retArgT!dchar(100) == "(dchar)"); 68 69 v = V("S", 5); 70 assert(v._is!S); 71 assert(v.a == 5); 72 assert(v.b == "S"); 73 // members are returned by reference if possible 74 inc(v.a); 75 assert(v.a == 6); 76 v.b = "s"; 77 assert(v.b == "s"); 78 // alias this members are supported 79 v.d = 15; 80 assert(v.d == 15); 81 // method call support 82 assert(v.retArg(300)._is!double); 83 assert(v.retArg(300) == 300.0);
Algebraic implementation. For more portable code, it is higly recommeded to don't use this template directly. Instead, please use of Variant and Nullable, which sort types.