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 "attest.hpp"
8
14namespace sanisizer {
15
26template<typename Value_>
27class Cast {
29 Value_ my_x;
30
31public:
35 constexpr Cast(Value_ x) : my_x(x) {}
36
41 template<typename Output_>
42 constexpr operator Output_() const {
43 return cast<Output_>(my_x);
44 }
45};
46
56template<typename Integer_>
57class Exact {
58 static_assert(std::is_integral<Integer_>::value);
59 Integer_ my_x;
60
61public:
65 constexpr Exact(Integer_ x) : my_x(x) {}
66
70 constexpr operator Integer_() const {
71 return my_x;
72 }
73
79 template<typename Output_>
80 constexpr operator Output_() const = delete;
81};
82
83}
84
85#endif
Create compile-time attestations.
Safe casts of integer size.
Cast an integer in a function call.
Definition class.hpp:27
constexpr Cast(Value_ x)
Definition class.hpp:35
Do not cast an integer in a function call.
Definition class.hpp:57
constexpr Exact(Integer_ x)
Definition class.hpp:65
Sanitize sizes to avoid integer overflow.
Definition arithmetic.hpp:16
constexpr Dest_ cast(Value_ x)
Definition cast.hpp:46