1#ifndef SANISIZER_BOUNDED_HPP
2#define SANISIZER_BOUNDED_HPP
28template<
typename Integer_, Integer_ max_>
30 static_assert(std::is_integral<Integer_>::value);
31 static_assert(max_ >= 0);
50 static constexpr Integer_
max = max_;
63template<
typename Value_>
68 static constexpr bool value =
false;
77template<
typename Integer_, Integer_ max_>
82 static constexpr bool value =
true;
89template<
typename Integer_, Integer_ max_>
91 static constexpr bool value =
true;
95template<
typename Value_>
98template<
typename Value_>
101template<
typename Left_,
typename Right_>
105template<
bool safe_,
typename Max_, Max_ new_max_,
typename Value_>
106constexpr auto set_bound_internal(Value_ x) {
109 if constexpr(safe_) {
111 throw std::domain_error(
"input value exceeds the declared upper bound");
114 return Bounded<I<
decltype(val)>, new_max_>(val);
136template<
typename Max_, Max_ new_max_,
typename Value_>
138 return set_bound_internal<true, Max_, new_max_>(x);
153template<
typename MaxType_,
typename Value_>
169template<
typename Max_, Max_ new_max_,
typename Value_>
171 return set_bound_internal<false, Max_, new_max_>(x);
184template<
typename MaxType_,
typename Value_>
193template<
typename Integer_, Integer_ max_>
194using Attestation = Bounded<Integer_, max_>;
196template<
typename ... Args_>
197using is_Attestation = is_Bounded<Args_...>;
199template<
typename Max_, Max_ new_max_,
typename Value_>
202template<
typename MaxType_,
typename Value_>
205template<
typename Value_>
206Value_ attest_gez(Value_ x) {
return x; }
Sanitize sizes to avoid integer overflow.
Definition Bounded.hpp:15
constexpr bool is_greater_than(Left_ left, Right_ right)
Definition comparisons.hpp:91
constexpr auto get_value(const Value_ x)
Definition generics.hpp:23
constexpr auto set_bound_unsafe(Value_ x)
Definition Bounded.hpp:170
constexpr auto get_max()
Definition generics.hpp:39
constexpr auto set_bound_by_type(Value_ x)
Definition Bounded.hpp:154
constexpr auto set_bound_by_type_unsafe(Value_ x)
Definition Bounded.hpp:185
constexpr auto set_bound(Value_ x)
Definition Bounded.hpp:137
Bound the maximum possible value of an integer.
Definition Bounded.hpp:29
static constexpr Integer_ max
Definition Bounded.hpp:50
constexpr Bounded(Integer_ x)
Definition Bounded.hpp:37
Integer_ Integer
Definition Bounded.hpp:44
Integer_ value
Definition Bounded.hpp:55
Definition Bounded.hpp:64
static constexpr bool value
Definition Bounded.hpp:68