The OpenD Programming Language

Algebraic.get

Gets the value if not null. If this is in the null state, and the optional parameter fallback was provided, it will be returned. Without fallback, calling get with a null state is invalid.

When the fallback type is different from the Nullable type, get(T) returns the common type.

  1. auto get()
  2. inout(AllowedTypes[1]) get()
  3. inout(AllowedTypes[1]) get [@property setter]
    struct Algebraic(T__...)
    @property ref return inout
    static if(is(AllowedTypes[0] == typeof(null)))
    static if(AllowedTypes.length == 2)
    inout(AllowedTypes[1])
    get
    ()
    (
    auto ref inout(AllowedTypes[1]) fallback
    )
  4. auto ref get()
  5. template get(RetTypes...)
  6. alias get(Kind kind) = get!(AllowedTypes[kind])
  7. alias get(immutable(char)[] kind) = get!(__traits(getMember, Kind, kind))
  8. auto ref get()

Parameters

fallback inout(AllowedTypes[1])

the value to return in case the Nullable is null.

Return Value

Type: inout(AllowedTypes[1])

The value held internally by this Nullable.

Examples

enum E { a = "a", b = "b" }
Nullable!E f = E.a;
auto e = f.get();
static assert(is(typeof(e) == E), Nullable!E.AllowedTypes.stringof);
assert(e == E.a);

assert(f.get(E.b) == E.a);

f = null;
assert(f.get(E.b) == E.b);

Meta