import capstone.x86; alias SafeOpValue = TaggedUnion!(X86Register, "reg", long, "imm"); auto safeVal = SafeOpValue(X86Register.eip); assertThrown(safeVal.imm); // cannot access the `long` since a `X86Register` is currently stored safeVal.imm = 42; assertNotThrown(safeVal.imm); // can access the `long` now assertNotThrown(safeVal.get!long); // also accessible by type // Corresponding operations on a regular union go unnoticed union UnsafeOpValue{X86Register reg; long imm;} auto unsafeVal = UnsafeOpValue(X86Register.eip); assertNotThrown(unsafeVal.imm);
Constructs a TaggedUnion with the specifiedn types and identifiers
In contrast to a plain std.variant.Algebraic, this one is not only parameterised by types but also by identifiers. This enables access of the stored value via the identifiers - just as for regular unions.