sanisizer
Sanitize sizes to avoid integer overflow
Loading...
Searching...
No Matches
class.hpp
Go to the documentation of this file.
1#ifndef SANISIZER_CLASS_HPP
2#define SANISIZER_CLASS_HPP
3
4#include <type_traits>
5
6#include "cast.hpp"
7#include "generics.hpp"
8
14namespace sanisizer {
15
25template<typename Value_>
26class Cast {
27 Value_ my_x;
28
29public:
33 constexpr Cast(Value_ x) : my_x(x) {}
34
39 template<typename Output_>
40 constexpr operator Output_() const {
41 return cast<Output_>(my_x);
42 }
43};
44
54template<typename Integer_>
55class Exact {
56 static_assert(std::is_integral<Integer_>::value);
57 Integer_ my_x;
58
59public:
63 constexpr Exact(Integer_ x) : my_x(x) {}
64
68 constexpr operator Integer_() const {
69 return my_x;
70 }
71
77 template<typename Output_>
78 constexpr operator Output_() const = delete;
79};
80
81}
82
83#endif
Safe casts of integer size.
Cast an integer in a function call.
Definition class.hpp:26
constexpr Cast(Value_ x)
Definition class.hpp:33
Do not cast an integer in a function call.
Definition class.hpp:55
constexpr Exact(Integer_ x)
Definition class.hpp:63
Generics for operating on integer representations.
Sanitize sizes to avoid integer overflow.
Definition Bounded.hpp:15
constexpr Dest_ cast(Value_ x)
Definition cast.hpp:59