diff --git a/cpp/core/app.cpp b/cpp/core/app.cpp index 3594d95e79..0d8b6c1790 100644 --- a/cpp/core/app.cpp +++ b/cpp/core/app.cpp @@ -1296,30 +1296,32 @@ int64_t App::ParsedArgument::as_int() const { } return static_cast(std::distance(choices.begin(), it)); } - assert(0); - return (0); + + assert(arg->type == Various); + return to(p); } default_type App::ParsedArgument::as_float() const { - assert(arg->type == Float); + assert(arg->type == Float || arg->type == Various); const default_type retval = to(p); - const auto range = std::get(arg->limits); - if (retval < range.min || retval > range.max) { - std::string msg("value supplied for "); - if (opt) - msg += std::string("option \"") + opt->id; - else - msg += std::string("argument \"") + arg->id; - msg += "\" is out of bounds (valid range: " + str(range.min) + " to " + str(range.max) + - ", value supplied: " + str(retval) + ")"; - throw Exception(msg); + if (arg->type == Float) { + const auto range = std::get(arg->limits); + if (retval < range.min || retval > range.max) { + std::string msg("value supplied for "); + if (opt) + msg += std::string("option \"") + opt->id; + else + msg += std::string("argument \"") + arg->id; + msg += "\" is out of bounds (valid range: " + str(range.min) + " to " + str(range.max) + + ", value supplied: " + str(retval) + ")"; + throw Exception(msg); + } } - return retval; } std::vector ParsedArgument::as_sequence_int() const { - assert(arg->type == IntSeq); + assert(arg->type == IntSeq || arg->type == Various); try { return parse_ints(p); } catch (Exception &e) { @@ -1329,7 +1331,7 @@ std::vector ParsedArgument::as_sequence_int() const { } std::vector ParsedArgument::as_sequence_uint() const { - assert(arg->type == IntSeq); + assert(arg->type == IntSeq || arg->type == Various); try { return parse_ints(p); } catch (Exception &e) { @@ -1339,7 +1341,7 @@ std::vector ParsedArgument::as_sequence_uint() const { } std::vector ParsedArgument::as_sequence_float() const { - assert(arg->type == FloatSeq); + assert(arg->type == FloatSeq || arg->type == Various); try { return parse_floats(p); } catch (Exception &e) { diff --git a/cpp/core/cmdline_option.h b/cpp/core/cmdline_option.h index 978d570d6b..8c5bda7308 100644 --- a/cpp/core/cmdline_option.h +++ b/cpp/core/cmdline_option.h @@ -122,9 +122,10 @@ class Argument { struct FloatRange { default_type min, max; }; + struct VoidRange {}; //! a structure to store the various parameters of the Argument - using Limits = std::variant, IntRange, FloatRange>; + using Limits = std::variant, IntRange, FloatRange, VoidRange>; Limits limits; operator bool() const { return id.empty(); } @@ -279,6 +280,7 @@ class Argument { Argument &type_various() { assert(type == Undefined); type = Various; + limits = VoidRange(); return *this; }