23#ifndef TYPES_TRAITS_HH
24#define TYPES_TRAITS_HH
49 static constexpr bool IS_INT =
false;
53 static constexpr size_t SIZE = 0;
57 template<
typename T_,
bool IS_SIGNED_>
struct Type_trait_int
59 static constexpr bool IS_INT =
true;
60 static constexpr bool IS_SIGNED = IS_SIGNED_;
61 static constexpr size_t SIZE =
sizeof(T_);
64 template<>
struct Type_trait<uint8_t> : Type_trait_int<uint8_t, false> {};
65 template<>
struct Type_trait<uint16_t> : Type_trait_int<uint16_t, false> {};
66 template<>
struct Type_trait<uint32_t> : Type_trait_int<uint32_t, false> {};
67 template<>
struct Type_trait<uint64_t> : Type_trait_int<uint64_t, false> {};
68 template<>
struct Type_trait<int8_t> : Type_trait_int<int8_t, true> {};
69 template<>
struct Type_trait<int16_t> : Type_trait_int<int16_t, true> {};
70 template<>
struct Type_trait<int32_t> : Type_trait_int<int32_t, true> {};
71 template<>
struct Type_trait<int64_t> : Type_trait_int<int64_t, true> {};
82 return TRAIT::IS_INT && (TRAIT::SIZE <=
sizeof(uint16_t)) && (!TRAIT::IS_SIGNED);
95 static void constraints(T* p)
101 UNUSED void (*p)(T*) = constraints;
121 template<
typename T>
struct remove_reference<T&&>
129 constexpr uint8_t uint_size_in_val(uint64_t value)
131 return (value & 0xFFFF'FFFF'0000'0000ULL ? 8 :
132 value & 0x0000'0000'FFFF'0000ULL ? 4 :
133 value & 0x0000'0000'0000'FF00ULL ? 2 : 1);
135 template<u
int8_t
bytes>
struct UnsignedInt
140 template<>
struct UnsignedInt<8>
142 using UTYPE = uint64_t;
143 using STYPE = int64_t;
145 template<>
struct UnsignedInt<4>
147 using UTYPE = uint32_t;
148 using STYPE = int32_t;
150 template<>
struct UnsignedInt<2>
152 using UTYPE = uint16_t;
153 using STYPE = int16_t;
155 template<>
struct UnsignedInt<1>
157 using UTYPE = uint8_t;
158 using STYPE = int8_t;
172 using SIGNED_TYPE =
typename UnsignedInt<uint_size_in_val(VAL)>::STYPE;
Useful defines GCC specific attributes.
#define UNUSED
Specific GCC attribute to declare an argument or variable unused, so that the compiler does not emit ...
Defines traits and utility methods for standard types, like uint16_t.
static constexpr bool is_uint8_or_uint16()
Check if a given type is uint8_t or uint16_t.
Find the smallest integral types, signed and unsigned, tha can hold a given value.
typename UnsignedInt< uint_size_in_val(VAL)>::UTYPE UNSIGNED_TYPE
The smallest unsigned integral type that can hold VAL.
typename UnsignedInt< uint_size_in_val(VAL)>::STYPE SIGNED_TYPE
The smallest signed integral type that can hold VAL.
This trait allows static checks (at compile-time) of properties of various types.
static constexpr bool IS_INT
Indicates if T is an integer type.
static constexpr bool IS_SIGNED
Indicates if T is a signed integer type.
static constexpr size_t SIZE
Indicates the size in bytes of T.
Utility class that checks, at compile-time, that type T is a subtype of type B.
Remove a reference from the given type.
T type
The type T without reference.