A validator that checks whether a value is inside a list of valid values. More...
#include <sharg/validators.hpp>
Public Types | |
using | option_value_type = option_value_t |
Type of values that are tested by validator. | |
Public Member Functions | |
void | operator() (option_value_type const &cmp) const |
Tests whether cmp lies inside values. More... | |
template<std::ranges::forward_range range_type> requires std::convertible_to<std::ranges::range_value_t<range_type>, option_value_type> && (!std::same_as<std::remove_cvref_t<range_type>, std::filesystem::path>) | |
void | operator() (range_type const &range) const |
Tests whether every element in range lies inside values. More... | |
std::string | get_help_page_message () const |
Returns a message that can be appended to the (positional) options help page info. More... | |
Constructors, destructor and assignment | |
value_list_validator ()=default | |
Defaulted. | |
value_list_validator (value_list_validator const &)=default | |
Defaulted. | |
value_list_validator (value_list_validator &&)=default | |
Defaulted. | |
value_list_validator & | operator= (value_list_validator const &)=default |
Defaulted. | |
value_list_validator & | operator= (value_list_validator &&)=default |
Defaulted. | |
~value_list_validator ()=default | |
Defaulted. | |
template<std::ranges::forward_range range_type> requires std::constructible_from<option_value_type, std::ranges::range_rvalue_reference_t<range_type>> | |
value_list_validator (range_type rng) | |
Constructing from a range. More... | |
template<typename... option_types> requires ((std::constructible_from<option_value_type, option_types> && ...)) | |
value_list_validator (option_types &&... opts) | |
Constructing from a parameter pack. More... | |
Related Functions | |
(Note that these are not member functions.) | |
Type deduction guides | |
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. | |
A validator that checks whether a value is inside a list of valid values.
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.
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.
|
stable-apiinline |
Constructing from a range.
range_type | The type of range; must model std::ranges::forward_range and value_list_validator::option_value_type must be constructible from the rvalue reference type of the given range. |
[in] | rng | The range of valid values to test. |
|
stable-apiinline |
Constructing from a parameter pack.
option_types | The type of option values in the parameter pack; The value_list_validator::option_value_type must be constructible from each type in the parameter pack. |
[in] | opts | The parameter pack values. |
|
stable-apiinline |
Returns a message that can be appended to the (positional) options help page info.
|
stable-apiinline |
Tests whether cmp lies inside values.
cmp | The input value to check. |
sharg::validation_error |
|
stable-apiinline |
Tests whether every element in range
lies inside values.
range_type | The type of range to check; must model std::ranges::forward_range. |
range | The input range to iterate over and check every element. |
sharg::validation_error |