Compound.get

Gets the element at the given index, if exists and can be casted to T. Otherwise evaluates and returns defaultValue.

  1. T get(string name, T defaultValue)
  2. T get(string name, E defaultValue)
    class Compound
    pure @safe
    T
    get
    (
    T : Tag
    E
    )
    (
    string name
    ,)
    if (
    !is(T == E) &&
    __traits(compiles, new T(defaultValue))
    )

Return Value

Type: T

the named tag of type T or defaultValue if the conversion fails

Examples

auto compound = new Compound(new Named!String("test", "value"));
assert(is(typeof(compound["test"]) == NamedTag));
assert(is(typeof(compound.get!String("test", null)) == String));
assert(compound.get!String("failed", new String("failed")) == new String("failed"));
assert(compound.get!String("?", "string") == new String("string"));

Meta