Construction from value.
Is true iff a pointer to a T can be stored.
Assignment from that.
1 import std.meta : AliasSeq; 2 3 alias Types = AliasSeq!(byte, short, int, long, 4 ubyte, ushort, uint, ulong, 5 float, double, real, 6 char, wchar, dchar); 7 8 alias V = VariantPointerTo!Types; 9 10 V v; 11 assert(v.isNull); 12 v = null; 13 assert(v.isNull); 14 assert(!v); 15 16 foreach (T; Types) 17 { 18 static assert(!__traits(compiles, { T[] a; v = &a; })); 19 static assert(!__traits(compiles, { v.peek!(T[]*); })); 20 21 // assignment from stack pointer 22 T a = 73; 23 T a_ = 73; 24 v = &a; 25 assert(v == &a); 26 assert(v != &a_); 27 assert(v); 28 foreach (U; Types) 29 { 30 static if (is(T == U)) 31 { 32 assert(v.peek!U); 33 assert(*(v.peek!U) == a); 34 } 35 else 36 assert(!v.peek!U); 37 } 38 39 // assignment from heap pointer 40 T* b = new T; 41 T* b_ = new T; 42 *b = 73; 43 *b_ = 73; 44 v = b; 45 assert(v == b); 46 assert(v != b_); 47 assert(v); 48 foreach (U; Types) 49 { 50 static if (is(T == U)) 51 { 52 assert(v.peek!U); 53 assert(*(v.peek!U) == *b); 54 } 55 else 56 assert(!v.peek!U); 57 } 58 59 }
std.bitmanip.taggedPointer.
A typed pointer to a variant of Types, packed into a word (size_t).