sanisizer
Sanitize sizes to avoid integer overflow
Loading...
Searching...
No Matches
generics.hpp
Go to the documentation of this file.
1#ifndef SANISIZER_GENERICS_HPP
2#define SANISIZER_GENERICS_HPP
3
4#include <limits>
5#include <type_traits>
6
7#include "Bounded.hpp"
8#include "Constant.hpp"
9
15namespace sanisizer {
16
22template<typename Value_>
23constexpr auto get_value(const Value_ x) {
24 if constexpr(std::is_integral<Value_>::value) {
25 return x;
26 } else if constexpr(is_Bounded<Value_>::value) {
27 return x.value;
28 } else {
29 static_assert(is_Constant<Value_>::value);
30 return Value_::value;
31 }
32}
33
38template<typename Value_>
39constexpr auto get_max() {
40 if constexpr(std::is_integral<Value_>::value) {
41 return std::numeric_limits<Value_>::max();
42 } else if constexpr(is_Bounded<Value_>::value) {
43 return Value_::max;
44 } else {
45 static_assert(is_Constant<Value_>::value);
46 return Value_::value;
47 }
48}
49
50}
51
52#endif
Specify compile-time bounds on integers.
Specify a constant integer.
Sanitize sizes to avoid integer overflow.
Definition Bounded.hpp:15
constexpr auto get_value(const Value_ x)
Definition generics.hpp:23
constexpr auto get_max()
Definition generics.hpp:39
Definition Bounded.hpp:64
Definition Constant.hpp:46