SafeUnion

Constructs a SafeUnion wrapping the specified union type

Enables access of the stored value through the field names of the wrapped union.

template SafeUnion (
U
) if (
is(U == union)
) {}

Examples

1 import capstone.api;
2 import capstone.x86;
3 
4 auto cs = new CapstoneX86(ModeFlags(Mode.bit32));
5 auto x86reg = new X86Register(cs, X86RegisterId.eip);
6 
7 SafeUnion!X86OpValue safeVal;
8 assertThrown(safeVal.imm);    	   // Not initialised
9 safeVal.reg = x86reg;
10 assertThrown(safeVal.imm);    	   // cannot access the `long` since a `X86Register` is currently stored
11 safeVal.imm = 42;
12 assertNotThrown(safeVal.imm);      // can access the `long` now
13 
14 // Corresponding operations on a regular union go unnoticed
15 X86OpValue unsafeVal;
16 unsafeVal.reg = x86reg;
17 assertNotThrown(unsafeVal.imm);

Meta