TaggedUnion

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.

Members

Aliases

Types
alias Types = staticMap!(extractType, fieldSpecs)
Undocumented in source.
extractName
alias extractName(alias spec) = spec.name
Undocumented in source.
extractType
alias extractType(alias spec) = spec.Type
Undocumented in source.
fieldSpecs
alias fieldSpecs = parseSpecs!Specs
Undocumented in source.
names
alias names = staticMap!(extractName, fieldSpecs)
Undocumented in source.

Structs

TaggedUnion
struct TaggedUnion
Undocumented in source.

Templates

FieldSpec
template FieldSpec(T, string s)
Undocumented in source.
parseSpecs
template parseSpecs(Specs...)
Undocumented in source.

Examples

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);

Meta