-
Notifications
You must be signed in to change notification settings - Fork 5
/
std_saturating_awareness.hpp
52 lines (43 loc) · 1.69 KB
/
std_saturating_awareness.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <cstddef>
#include <cstdint>
#include <limits>
#include <type_traits>
#include <utility>
#include "./forward_decl.hpp"
namespace std {
// Extend the standard type traits to handle the new sat types.
template <typename T, T _min, T _max>
class decay<saturating::type<T, _min, _max>> {
public:
using type = typename decay<T>::type;
};
template <typename T, T _min, T _max>
struct is_unsigned<saturating::type<T, _min, _max>> {
static constexpr decltype(auto) value = is_unsigned_v<T>;
};
template <typename T, T _min, T _max>
struct is_signed<saturating::type<T, _min, _max>> {
static constexpr decltype(auto) value = is_signed_v<T>;
};
template <typename T, T _min, T _max>
struct is_integral<saturating::type<T, _min, _max>> {
static constexpr decltype(auto) value = is_integral_v<T>;
};
template <typename T, T _min, T _max>
struct is_floating_point<saturating::type<T, _min, _max>> {
static constexpr decltype(auto) value = is_floating_point_v<T>;
};
template <typename T, T _min, T _max>
struct is_arithmetic<saturating::type<T, _min, _max>> {
static constexpr decltype(auto) value = is_arithmetic_v<T>;
};
template <typename T, T _min, T _max>
class numeric_limits<saturating::type<T, _min, _max>> {
// TODO: implement the rest of: http://en.cppreference.com/w/cpp/types/numeric_limits
public:
static constexpr std::decay_t<T> min() noexcept { return _min; }
static constexpr std::decay_t<T> lowest() noexcept { return _min; }
static constexpr std::decay_t<T> max() noexcept { return _max; }
};
} // namespace std