|
(Note that these are not member symbols.)
|
|
template<typename option_type , typename... option_types> |
| value_list_validator (option_type, option_types...) -> value_list_validator< std::string > |
| Given a parameter pack of types that are convertible to std::string, delegate to value type std::string.
|
|
template<typename range_type > |
| value_list_validator (range_type &&rng) -> value_list_validator< std::string > |
| Deduction guide for ranges over a value type convertible to std::string.
|
|
template<typename option_type , typename... option_types> |
| value_list_validator (option_type, option_types...) -> value_list_validator< option_type > |
| Deduction guide for a parameter pack.
|
|
template<typename range_type > |
| value_list_validator (range_type &&rng) -> value_list_validator< std::ranges::range_value_t< range_type > > |
| Deduction guide for ranges.
|
|
template<parsable option_value_t>
class sharg::value_list_validator< option_value_t >
A validator that checks whether a value is inside a list of valid values.
- Template Parameters
-
option_value_t | The type the validator is called on. Must model sharg::parsable. |
On construction, the validator must receive a range or parameter pack of valid values. The class then acts as a functor that throws a sharg::validation_error exception whenever a given value is not in the list.
- Note
- In order to simplify the chaining of validators, the option value type is deduced to
std::string
if the range's value type is convertible to it. Otherwise, the option value type is deduced to the value type of the range.
int main(int argc, char const ** argv)
{
int myint;
myparser.add_option(myint,
.long_id = "integer",
.description = "Give me a number.",
.validator = my_validator});
try
{
myparser.parse();
}
{
return -1;
}
std::cerr <<
"integer given by user passed validation: " << myint <<
"\n";
return 0;
}
Meta-header for the Parser module .
Parser exception that is thrown whenever there is an error while parsing the command line arguments.
Definition exceptions.hpp:40
The Sharg command line parser.
Definition parser.hpp:154
A validator that checks whether a value is inside a list of valid values.
Definition validators.hpp:175
Option struct that is passed to the sharg::parser::add_option() function.
Definition config.hpp:43
char short_id
The short identifier for the option (e.g. 'a', making the option callable via -a).
Definition config.hpp:53
This entity is stable. Since version 1.0.