7 #include "arg_router/exception.hpp"
8 #include "arg_router/parsing/parsing.hpp"
9 #include "arg_router/policy/policy.hpp"
21 template <
typename ValueType,
typename LessThanCompare = std::less<ValueType>>
41 std::optional<value_type> max,
45 comp_{std::move(compare)}
62 template <
typename InputValueType,
typename... Parents>
64 [[maybe_unused]]
const Parents&... parents)
const
66 static_assert(
sizeof...(Parents) >= 1,
"Min/max value requires at least 1 parent");
68 using node_type = boost::mp11::mp_first<std::tuple<Parents...>>;
70 if (min_ && comp_(value, *min_)) {
72 parsing::node_token_type<node_type>()};
74 if (max_ && comp_(*max_, value)) {
76 parsing::node_token_type<node_type>()};
81 std::optional<value_type> min_;
82 std::optional<value_type> max_;
97 template <
typename MinType,
typename MaxType>
100 static_assert(!(std::is_void_v<MinType> && std::is_void_v<MaxType>),
101 "MinType and MaxType cannot both be void");
107 if constexpr (!std::is_void_v<MinType>) {
108 static_assert(traits::has_value_type_v<MinType>,
"MinType must have a value_type");
109 static_assert(std::is_integral_v<typename MinType::value_type> ||
110 std::is_enum_v<typename MinType::value_type>,
111 "MinType value_type must be integrals or enums");
113 if constexpr (!std::is_void_v<MaxType>) {
114 static_assert(traits::has_value_type_v<MaxType>,
"MaxType must have a value_type");
115 static_assert(std::is_integral_v<typename MaxType::value_type> ||
116 std::is_enum_v<typename MaxType::value_type>,
117 "MaxType value_type must be integrals or enums");
120 if constexpr (!std::is_void_v<MinType> && !std::is_void_v<MaxType>) {
122 std::is_same_v<typename MinType::value_type, typename MaxType::value_type>,
123 "MinType and MaxType must have the same value_type");
124 static_assert(MinType::value <= MaxType::value,
125 "MinType must be less than or equal to MaxType");
134 template <
typename T = MinType>
137 std::enable_if_t<!std::is_void_v<T>>* =
nullptr) noexcept
139 return MinType::value;
147 template <
typename T = MaxType>
150 std::enable_if_t<!std::is_void_v<T>>* =
nullptr) noexcept
152 return MaxType::value;
163 template <
typename InputValueType,
typename... Parents>
165 [[maybe_unused]]
const Parents&... parents)
const
167 static_assert(
sizeof...(Parents) >= 1,
"Min/max value requires at least 1 parent");
169 using node_type = boost::mp11::mp_first<std::tuple<Parents...>>;
171 if constexpr (!std::is_void_v<MinType>) {
174 parsing::node_token_type<node_type>()};
177 if constexpr (!std::is_void_v<MaxType>) {
180 parsing::node_token_type<node_type>()};
195 template <
typename ValueType,
typename LessThanCompare = std::less<ValueType>>
198 LessThanCompare&& compare = LessThanCompare{}) noexcept
200 return min_max_value_t<ValueType, LessThanCompare>{std::forward<ValueType>(min),
201 std::forward<ValueType>(max),
202 std::forward<LessThanCompare>(compare)};
213 template <
typename ValueType,
typename LessThanCompare = std::less<ValueType>>
215 LessThanCompare&& compare = LessThanCompare{}) noexcept
217 return min_max_value_t<ValueType, LessThanCompare>{std::forward<ValueType>(min),
219 std::forward<LessThanCompare>(compare)};
230 template <
typename ValueType,
typename LessThanCompare = std::less<ValueType>>
232 LessThanCompare&& compare = LessThanCompare{}) noexcept
234 return min_max_value_t<ValueType, LessThanCompare>{{},
235 std::forward<ValueType>(max),
236 std::forward<LessThanCompare>(compare)};
245 template <auto Min, auto Max>
273 template <
typename ValueType,
typename LessThanCompare>
274 struct is_policy<min_max_value_t<ValueType, LessThanCompare>> : std::true_type {
277 template <
typename ValueType>
278 struct is_policy<min_max_value_t<ValueType>> : std::true_type {
281 template <
typename MinType,
typename MaxType>
282 struct is_policy<min_max_value_ct<MinType, MaxType>> : std::true_type {
constexpr static auto minimum_value(std::enable_if_t<!std::is_void_v< T >> *=nullptr) noexcept
min_max_value_ct() noexcept
constexpr static auto maximum_value(std::enable_if_t<!std::is_void_v< T >> *=nullptr) noexcept
void validation_phase(const InputValueType &value, [[maybe_unused]] const Parents &... parents) const
constexpr min_max_value_t(std::optional< value_type > min, std::optional< value_type > max, less_than_compare compare=less_than_compare{}) noexcept
constexpr const less_than_compare & comp() const noexcept
LessThanCompare less_than_compare
void validation_phase(const InputValueType &value, [[maybe_unused]] const Parents &... parents) const
constexpr auto max_value(ValueType &&max, LessThanCompare &&compare=LessThanCompare{}) noexcept
constexpr auto min_max_value(ValueType &&min, ValueType &&max, LessThanCompare &&compare=LessThanCompare{}) noexcept
constexpr auto min_value(ValueType &&min, LessThanCompare &&compare=LessThanCompare{}) noexcept
std::integral_constant< decltype(Value), Value > integral_constant
@ minimum_value_not_reached
Parsed value is below the minimum.
@ maximum_value_exceeded
Parsed value is above the maximum.