Algebraic.get

Gets an algebraic subset.

  1. auto get()
  2. inout(AllowedTypes[1]) get()
  3. inout(AllowedTypes[1]) get [@property setter]
  4. auto ref get()
    struct Algebraic(_Types...)
    ref return @property
    get
    (
    R : Algebraic!RetTypes
    this This
    RetTypes...
    )
    ()
    if (
    allSatisfy!(Contains!AllowedTypes, Algebraic!RetTypes.AllowedTypes)
    )
  5. template get(RetTypes...)
  6. alias get(Kind kind) = get!(AllowedTypes[kind])
  7. auto ref get()

Throws

Exception if the storage contains value of the type that isn't represented in the allowed type set of the requested algebraic.

Examples

alias Float = Variant!(float, double);
alias Int = Variant!(long, int);
alias Number = Variant!(Float.AllowedTypes, Int.AllowedTypes);

Number number = 3.0;
auto fp = number.get!Float;
static assert(is(typeof(fp) == Float));
assert(fp == 3.0);

// type list overload
number = 12L;
auto integer = number.get!(int, long);
static assert(is(typeof(integer) == Int));
assert(integer == 12L);

Meta