VariantPointerTo

A typed pointer to a variant of Types, packed into a word (size_t).

Constructors

this
this(T* value)
this(typeof(null) value)

Construction from value.

Members

Aliases

S
alias S = size_t
Undocumented in source.

Enums

canStorePointerTo
eponymoustemplate canStorePointerTo(T)

Is true iff a pointer to a T can be stored.

indexOf
eponymoustemplate indexOf(T)
Undocumented in source.

Functions

isNull
bool isNull()
Undocumented in source. Be warned that the author may not have intended to support it.
opAssign
auto ref opAssign(T* that)
auto ref opAssign(typeof(null) that)

Assignment from that.

opCast
bool opCast()
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(T* that)
Undocumented in source. Be warned that the author may not have intended to support it.
toHash
auto toHash()
Undocumented in source. Be warned that the author may not have intended to support it.

Manifest constants

typeBits
enum typeBits;
Undocumented in source.
typeMask
enum typeMask;
Undocumented in source.
typeShift
enum typeShift;
Undocumented in source.

Properties

peek
inout(T)* peek [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
ptr
inout(void)* ptr [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

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 }

See Also

std.bitmanip.taggedPointer.

Meta