7 #include "arg_router/dependency/detail.hpp"
8 #include "arg_router/policy/multi_stage_value.hpp"
19 template <
typename... Params>
20 class one_of_t :
public detail::basic_one_of_t<AR_STRING("One of: "), Params...>
22 using parent_type = detail::basic_one_of_t<AR_STRING(
"One of: "), Params...>;
24 static_assert(boost::mp11::mp_none_of<
typename parent_type::children_type,
26 "one_of children must not use a multi_stage_value policy");
29 boost::mp11::mp_rename<typename parent_type::basic_value_type, std::variant>;
32 !parent_type::template any_phases_v<variant_type, policy::has_validation_phase_method>,
33 "one_of does not support policies with validation phases; as it delegates those to its "
37 using typename parent_type::children_type;
38 using typename parent_type::policies_type;
42 using value_type = std::conditional_t<(std::variant_size_v<variant_type> == 1),
43 std::variant_alternative_t<0, variant_type>,
47 template <
bool Flatten>
51 using label = AR_STRING_SV(parent_type::display_name());
52 using description = AR_STRING(
"");
53 using children =
typename parent_type::template children_help_data_type<Flatten>::children;
55 template <
typename OwnerNode,
typename FilterFn>
59 return parent_type::template children_help_data_type<Flatten>::runtime_children(
61 std::forward<FilterFn>(f));
69 constexpr
explicit one_of_t(Params... params) noexcept : parent_type{std::move(params)...} {}
83 template <
typename Validator,
bool HasTarget,
typename... Parents>
84 [[nodiscard]] std::optional<parsing::parse_target>
pre_parse(
86 const Parents&... parents)
const
90 const auto validator = [&](
const auto& child,
const auto&... parents) {
91 using child_type = std::decay_t<decltype(child)>;
93 auto type_hash = utility::type_hash<child_type>();
95 if (type_hash != *last_typeid_) {
97 parsing::node_token_type<one_of_t>()};
100 last_typeid_ = type_hash;
103 return pre_parse_data.validator()(child, parents...);
107 if constexpr (pre_parse_data.has_target) {
114 auto found = std::optional<parsing::parse_target>{};
116 [&](
auto ,
const auto& child) {
118 found = child.pre_parse(*wrapper, parents...);
122 validator(child, parents...);
132 mutable std::optional<std::size_t> last_typeid_;
142 template <
typename... Params>
143 [[nodiscard]] constexpr
auto one_of(Params... params) noexcept
145 return one_of_t{std::move(params)...};
std::conditional_t<(std::variant_size_v< variant_type >==1), std::variant_alternative_t< 0, variant_type >, variant_type > value_type
std::optional< parsing::parse_target > pre_parse(parsing::pre_parse_data< Validator, HasTarget > pre_parse_data, const Parents &... parents) const
constexpr one_of_t(Params... params) noexcept
constexpr auto one_of(Params... params) noexcept
constexpr std::enable_if_t< traits::is_tuple_like_v< std::decay_t< Tuple > > > tuple_iterator(F &&f, Tuple &&tuple)
std::vector< T, config::allocator< T > > vector
@ one_of_selected_type_mismatch