ArgValue.opCast

T opCast(T)() if (is(T == string) || is(T == bool) || is(T == int) || is(T == long) || is(T == double) || is(T == float) || is( T == const(string[])) || is(T == ArgValue)) const @safe pure nothrow @nogc

Explicitly casts this ArgValue to the requested type using cast(T).

This provides D-idiomatic conversion syntax on top of the existing as!T helper. Supported target types are the same as for as!T:

  • string → string value or null if not a string
  • bool → boolean value or false if not a bool
  • int → integer value or 0 if not an int
  • long → long value or 0L if not an integer
  • double → double value or 0.0 if not a double
  • float → float value or 0.0f if not a double
  • const(string[]) → list value or null if not a list

Parameters

TTarget type to cast to.

Returns

The value converted to type T using the same fallback semantics as as!T.

Examples

string file   = cast(string) args["<file>"];
bool verbose  = cast(bool) args["--verbose"];
int count     = cast(int) args["--count"];
auto files    = cast(const(string[])) args["<file>"];