get

fnT get(T)(const ref ArgMap args, string key, auto ref T defaultValue) if (is(T == string) || is(T == bool) || is(T == int) || is(T == long) || is(T == double) || is(T == float) || is( T == const(string[])))

Retrieves a value from the argument map with a default fallback.

This is a convenience helper that allows idiomatic access to optional arguments without manual presence checks. It returns the stored value when a key exists and the underlying ArgValue is of the requested type; otherwise it returns the provided defaultValue.

Supported target types are:

  • string
  • bool
  • int
  • long
  • double
  • float
  • const(string[])

Notes:

  • If the key is absent in the map, defaultValue is returned.
  • If the key is present but holds NONE (null) or a different type,

defaultValue is returned.

  • This function is intended to be used via UFCS:

Examples

ArgMap args;
args["--verbose"] = ArgValue(true);
args["<file>"] = ArgValue("data.txt");

// Retrieve with defaults
bool verbose = args.get("--verbose", false);        // true
string file = args.get("<file>", "default.txt");   // "data.txt"
int count = args.get("--count", 0);                 // 0 (missing -> default)
const(string[]) files = args.get("<file>", ["a"]); // type mismatch -> default