7 #include "arg_router/policy/validator.hpp"
9 namespace arg_router::policy::validation::utility
15 template <
template <
typename...>
typename T,
16 template <
template <
typename...>
typename...>
18 template <
typename...>
21 using type = U<V..., T>;
23 explicit appender_t([[maybe_unused]] U<V...> rule_type) {}
26 template <
template <
typename...>
typename T,
27 template <
template <
typename...>
typename...>
29 template <
typename...>
31 auto appender(U<V...>&& rule_type)
33 return appender_t<T, U, V...>{std::forward<U<V...>>(rule_type)};
46 template <
typename RuleType,
typename Rules>
47 constexpr std::size_t find_index_of_rule_type() noexcept
49 return boost::mp11::mp_find_if_q<
51 boost::mp11::mp_bind<std::is_same,
53 boost::mp11::mp_bind<boost::mp11::mp_first, boost::mp11::_1>>>::value;
62 template <std::
size_t I,
typename Rule,
typename Rules>
64 static_assert(I <= std::tuple_size_v<Rules>,
"I must be less than or equal Rules size");
67 using type = boost::mp11::mp_insert_c<Rules, I, Rule>;
76 template <std::
size_t I,
typename Rule,
typename Rules>
84 template <std::
size_t I,
typename Rules>
86 static_assert(I < std::tuple_size_v<Rules>,
"I must be less than Rules size");
89 using type = boost::mp11::mp_erase_c<Rules, I, I + 1>;
97 template <std::
size_t I,
typename Rules>
106 template <
typename RuleType,
typename Rules>
109 constexpr
static auto I = find_index_of_rule_type<RuleType, Rules>();
110 constexpr
static auto found = I < std::tuple_size_v<Rules>;
114 using type = boost::mp11::mp_eval_if_c<!found,
116 boost::mp11::mp_erase,
127 template <
typename RuleType,
typename Rules>
136 template <std::
size_t I,
typename Rule,
typename Rules>
138 static_assert(I < std::tuple_size_v<Rules>,
"I must be less than Rules size");
141 using type = boost::mp11::mp_replace_at_c<Rules, I, Rule>;
150 template <std::
size_t I,
typename Rule,
typename Rules>
159 template <
typename RuleType,
typename Rule,
typename Rules>
162 constexpr
static auto I = find_index_of_rule_type<RuleType, Rules>();
163 static_assert(I < std::tuple_size_v<Rules>,
"RuleType cannot be found");
167 using type = update_rule_t<I, Rule, Rules>;
176 template <
typename RuleType,
typename Rule,
typename Rules>
201 template <std::size_t I,
template <
typename...>
typename T,
typename Rules>
204 static_assert(I < std::tuple_size_v<Rules>,
"I must be less than Rules size");
206 using rule = std::tuple_element_t<I, Rules>;
207 using rule_type = std::tuple_element_t<0, rule>;
208 using new_rule_type =
typename decltype(detail::appender<T>(std::declval<rule_type>()))::
type;
209 using new_rule = boost::mp11::mp_replace_at_c<rule, 0, new_rule_type>;
213 using type = boost::mp11::mp_replace_at_c<Rules, I, new_rule>;
222 template <std::size_t I,
template <
typename...>
typename T,
typename Rules>
231 template <
typename RuleType,
template <
typename...>
typename T,
typename Rules>
234 constexpr
static auto I = find_index_of_rule_type<RuleType, Rules>();
235 static_assert(I < std::tuple_size_v<Rules>,
"RuleType cannot be found");
239 using type = add_to_rule_types_t<I, T, Rules>;
248 template <
typename RuleType,
template <
typename...>
typename T,
typename Rules>
add_to_rule_types_t< I, T, Rules > type
boost::mp11::mp_replace_at_c< Rules, I, new_rule > type
boost::mp11::mp_eval_if_c<!found, Rules, boost::mp11::mp_erase, Rules, traits::integral_constant< I >, traits::integral_constant< I+1 > > type
update_rule_t< I, Rule, Rules > type
constexpr auto default_validator
std::integral_constant< decltype(Value), Value > integral_constant
boost::mp11::mp_insert_c< Rules, I, Rule > type
boost::mp11::mp_erase_c< Rules, I, I+1 > type
boost::mp11::mp_replace_at_c< Rules, I, Rule > type