Plaquette
 
Loading...
Searching...
No Matches
pq_traits.h
1/*
2 * pq_traits.h
3 *
4 * Minimal, AVR-safe type traits for Plaquette.
5 *
6 * (c) 2025 Sofian Audry :: info(@)sofianaudry(.)com
7 * (c) 2015 Thomas O Fredericks :: tof(@)t-o-f(.)info
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef PQ_TRAITS_H_
24#define PQ_TRAITS_H_
25
26namespace pq {
27
28// ---------- enable_if ----------
29
30// C++11-compatible enable_if_t.
31template <bool B, typename T = void>
32struct enable_if { };
33
34template <typename T>
35struct enable_if<true, T> { typedef T type; };
36
37template <bool B, typename T = void>
38using enable_if_t = typename enable_if<B, T>::type;
39
40// ---------- is_integral ----------
41
42#if defined(__has_include) && __has_include(<type_traits>)
43#include <type_traits>
44
45template <typename T>
46using is_integral = std::is_integral<T>;
47
48#else
49// Minimal is_integral (AVR-safe).
50template <typename T> struct is_integral { static const bool value = false; };
51
52template <> struct is_integral<bool> { static const bool value = true; };
53template <> struct is_integral<char> { static const bool value = true; };
54template <> struct is_integral<signed char> { static const bool value = true; };
55template <> struct is_integral<unsigned char> { static const bool value = true; };
56template <> struct is_integral<short> { static const bool value = true; };
57template <> struct is_integral<unsigned short> { static const bool value = true; };
58template <> struct is_integral<int> { static const bool value = true; };
59template <> struct is_integral<unsigned int> { static const bool value = true; };
60template <> struct is_integral<long> { static const bool value = true; };
61template <> struct is_integral<unsigned long> { static const bool value = true; };
62template <> struct is_integral<long long> { static const bool value = true; };
63template <> struct is_integral<unsigned long long> { static const bool value = true; };
64
65#endif
66
67// ---------- is_same ----------
68
69template <typename T, typename U>
70struct is_same { static const bool value = false; };
71template <typename T>
72struct is_same<T, T> { static const bool value = true; };
73
74// ---------- supports_modulo ----------
75
76// True for integral types excluding bool.
77template <typename T>
79 static const bool value = is_integral<T>::value && !is_same<T, bool>::value;
80};
81
82// ---------- remove_reference / remove_cv ----------
83
84template <typename T> struct remove_reference { typedef T type; };
85template <typename T> struct remove_reference<T&> { typedef T type; };
86#if __cplusplus >= 201103L
87template <typename T> struct remove_reference<T&&> { typedef T type; };
88#endif
89
90template <typename T> struct remove_const { typedef T type; };
91template <typename T> struct remove_const<const T> { typedef T type; };
92
93template <typename T> struct remove_volatile { typedef T type; };
94template <typename T> struct remove_volatile<volatile T> { typedef T type; };
95
96template <typename T>
97struct remove_cv {
98 typedef typename remove_const<typename remove_volatile<T>::type>::type type;
99};
100
101template <typename T>
103 typedef typename remove_cv<typename remove_reference<T>::type>::type type;
104};
105
106// ---------- always_false ----------
107
108template <typename>
109struct always_false { enum { value = 0 }; };
110
111} // namespace pq
112
113#endif
Definition pq_traits.h:109
Definition pq_traits.h:32
Definition pq_traits.h:50
Definition pq_traits.h:70
Definition pq_traits.h:90
Definition pq_traits.h:97
Definition pq_traits.h:102
Definition pq_traits.h:84
Definition pq_traits.h:93
Definition pq_traits.h:78