diff --git a/jngen.h b/jngen.h index ae2d58d..91702ab 100644 --- a/jngen.h +++ b/jngen.h @@ -231,6 +231,18 @@ bool getOpt(const std::string& name, T& var) { return readVariable(vmap[name], var); } +template +T getOptOr(size_t index, T def) { + getOpt(index, def); + return def; +} + +template +T getOptOr(const std::string& name, T def) { + getOpt(name, def); + return def; +} + inline void parseArgs(int argc, char *argv[]) { vmap = parseArguments(std::vector(argv + 1, argv + argc)); } @@ -316,6 +328,7 @@ int getPositional(Args&... args) { using jngen::parseArgs; using jngen::getOpt; +using jngen::getOptOr; using jngen::getPositional; diff --git a/options.h b/options.h index 015eb79..f16ab99 100644 --- a/options.h +++ b/options.h @@ -119,6 +119,18 @@ bool getOpt(const std::string& name, T& var) { return readVariable(vmap[name], var); } +template +T getOptOr(size_t index, T def) { + getOpt(index, def); + return def; +} + +template +T getOptOr(const std::string& name, T def) { + getOpt(name, def); + return def; +} + inline void parseArgs(int argc, char *argv[]) { vmap = parseArguments(std::vector(argv + 1, argv + argc)); } @@ -204,6 +216,7 @@ int getPositional(Args&... args) { using jngen::parseArgs; using jngen::getOpt; +using jngen::getOptOr; using jngen::getPositional;