1#ifndef SANISIZER_COMPARISONS_HPP
2#define SANISIZER_COMPARISONS_HPP
18template<
typename Integer_>
19constexpr auto as_unsigned(Integer_ x) {
20 static_assert(std::is_integral<Integer_>::value);
21 if constexpr(std::is_unsigned<Integer_>::value) {
24 return static_cast<typename std::make_unsigned<Integer_>::type
>(x);
42template<
typename Left_,
typename Right_>
43constexpr bool is_equal(Left_ left, Right_ right) {
58template<
typename Left_,
typename Right_>
74template<
typename Left_,
typename Right_>
90template<
typename Left_,
typename Right_>
106template<
typename Left_,
typename Right_>
122template<
typename First_,
typename Second_>
123constexpr auto min(First_ first, Second_ second) {
126 const bool first_larger = as_unsigned(fval) > as_unsigned(sval);
128 if constexpr(as_unsigned(
get_max<I<
decltype(fval)> >()) > as_unsigned(
get_max<I<
decltype(sval)> >())) {
132 return static_cast<I<decltype(sval)
> >(fval);
136 return static_cast<I<decltype(fval)
> >(sval);
154template<
typename First_,
typename Second_>
155constexpr auto max(First_ first, Second_ second) {
158 const bool first_larger = as_unsigned(fval) > as_unsigned(sval);
160 if constexpr(as_unsigned(
get_max<I<
decltype(fval)> >()) > as_unsigned(
get_max<I<
decltype(sval)> >())) {
164 return static_cast<I<decltype(fval)
> >(sval);
168 return static_cast<I<decltype(sval)
> >(fval);
Generics for operating on integer representations.
Sanitize sizes to avoid integer overflow.
Definition Bounded.hpp:15
constexpr bool is_greater_than(Left_ left, Right_ right)
Definition comparisons.hpp:91
constexpr bool is_equal(Left_ left, Right_ right)
Definition comparisons.hpp:43
constexpr auto get_value(const Value_ x)
Definition generics.hpp:23
constexpr auto max(First_ first, Second_ second)
Definition comparisons.hpp:155
constexpr bool is_greater_than_or_equal(Left_ left, Right_ right)
Definition comparisons.hpp:107
constexpr auto get_max()
Definition generics.hpp:39
constexpr bool is_less_than_or_equal(Left_ left, Right_ right)
Definition comparisons.hpp:75
constexpr auto min(First_ first, Second_ second)
Definition comparisons.hpp:123
constexpr bool is_less_than(Left_ left, Right_ right)
Definition comparisons.hpp:59