ArgValue.as

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

Returns the value converted to the specified type.

This template method provides idiomatic D-style type conversion, similar to other D libraries. Supported types are:

  • string - returns the string value or null
  • bool - returns the boolean value or false
  • int - returns the integer value or 0
  • long - returns the long value or 0L
  • double - returns the double value or 0.0
  • float - returns the float value or 0.0f
  • const(string[]) - returns the list value or null

Parameters

TThe target type to convert to.

Returns

The value converted to type T.

Example:

auto args = docopt(DOC, argv);
string file = args["<file>"].as!string;
bool verbose = args["--verbose"].as!bool;
int count = args["--count"].as!int;
const(string[]) files = args["<file>"].as!(const(string[]));