sanisizer
Sanitize sizes to avoid integer overflow
Loading...
Searching...
No Matches
comparisons.hpp
Go to the documentation of this file.
1#ifndef SANISIZER_COMPARISONS_HPP
2#define SANISIZER_COMPARISONS_HPP
3
4#include <type_traits>
5
11namespace sanisizer {
12
22template<typename Left_, typename Right_>
23constexpr bool is_equal(Left_ l, Right_ r) {
24 return static_cast<typename std::make_unsigned<Left_>::type>(l) == static_cast<typename std::make_unsigned<Right_>::type>(r);
25}
26
36template<typename Left_, typename Right_>
37constexpr bool is_less_than(Left_ l, Right_ r) {
38 return static_cast<typename std::make_unsigned<Left_>::type>(l) < static_cast<typename std::make_unsigned<Right_>::type>(r);
39}
40
50template<typename Left_, typename Right_>
51constexpr bool is_greater_than_or_equal(Left_ l, Right_ r) {
52 return !is_less_than(l, r);
53}
54
64template<typename Left_, typename Right_>
65constexpr bool is_greater_than(Left_ l, Right_ r) {
66 return static_cast<typename std::make_unsigned<Left_>::type>(l) > static_cast<typename std::make_unsigned<Right_>::type>(r);
67}
68
78template<typename Left_, typename Right_>
79constexpr bool is_less_than_or_equal(Left_ l, Right_ r) {
80 return !is_greater_than(l, r);
81}
82
83}
84
85#endif
Sanitize sizes to avoid integer overflow.
Definition arithmetic.hpp:14
constexpr bool is_less_than(Left_ l, Right_ r)
Definition comparisons.hpp:37
constexpr bool is_greater_than_or_equal(Left_ l, Right_ r)
Definition comparisons.hpp:51
constexpr bool is_greater_than(Left_ l, Right_ r)
Definition comparisons.hpp:65
constexpr bool is_less_than_or_equal(Left_ l, Right_ r)
Definition comparisons.hpp:79
constexpr bool is_equal(Left_ l, Right_ r)
Definition comparisons.hpp:23