HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
type_traits.hpp
1
2#pragma once
3
4#include <cstdint>
5#include <type_traits>
6
7namespace tt {
8
9template<typename T> struct is_numeric_integer : std::false_type {};
10template<> struct is_numeric_integer<signed char> : std::true_type {};
11template<> struct is_numeric_integer<unsigned char> : std::true_type {};
12template<> struct is_numeric_integer<signed short> : std::true_type {};
13template<> struct is_numeric_integer<unsigned short> : std::true_type {};
14template<> struct is_numeric_integer<signed int> : std::true_type {};
15template<> struct is_numeric_integer<unsigned int> : std::true_type {};
16template<> struct is_numeric_integer<signed long> : std::true_type {};
17template<> struct is_numeric_integer<unsigned long> : std::true_type {};
18template<> struct is_numeric_integer<signed long long> : std::true_type {};
19template<> struct is_numeric_integer<unsigned long long> : std::true_type {};
20
24template<typename T>
25inline constexpr bool is_numeric_integer_v = is_numeric_integer<T>::value;
26
27template<typename T> struct is_character : std::false_type {};
28template<> struct is_character<char> : std::true_type {};
29template<> struct is_character<wchar_t> : std::true_type {};
30template<> struct is_character<char16_t> : std::true_type {};
31template<> struct is_character<char32_t> : std::true_type {};
32
36template<typename T>
37inline constexpr bool is_character_v = is_character<T>::value;
38
39
40template<typename T, typename U>
42 using type = decltype(static_cast<T>(0) + static_cast<U>(0));
43};
44
45template<typename T, typename U>
46using make_promote_t = typename make_promote<T,U>::type;
47
48template<typename T, typename Ei=void>
50 using type = uintmax_t;
51};
52
53template<typename T>
54struct make_intmax<T,std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T>>> {
55 using type = uintmax_t;
56};
57
58template<typename T>
59struct make_intmax<T,std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>>> {
60 using type = intmax_t;
61};
62
63template<typename T>
64using make_intmax_t = typename make_intmax<T>::type;
65
66template<typename T> struct make_larger { using type = T; };
67template<> struct make_larger<signed long> { using type = signed long long; };
68template<> struct make_larger<signed int> { using type = signed long; };
69template<> struct make_larger<signed short> { using type = signed int; };
70template<> struct make_larger<signed char> { using type = signed short; };
71template<> struct make_larger<unsigned long> { using type = unsigned long long; };
72template<> struct make_larger<unsigned int> { using type = unsigned long; };
73template<> struct make_larger<unsigned short> { using type = unsigned int; };
74template<> struct make_larger<unsigned char> { using type = unsigned short; };
75template<> struct make_larger<double> { using type = long double; };
76template<> struct make_larger<float> { using type = double; };
77
78template<typename T>
79using make_larger_t = typename make_larger<T>::type;
80
81template<typename To, typename From, typename Ei=void>
82struct copy_cv {};
83
84template<typename To, typename From>
85struct copy_cv<To,From,std::enable_if_t<!std::is_const_v<From> && !std::is_volatile_v<From>>> {
86 using type = std::remove_cv_t<To>;
87};
88
89template<typename To, typename From>
90struct copy_cv<To,From,std::enable_if_t<!std::is_const_v<From> && std::is_volatile_v<From>>> {
91 using type = std::remove_cv_t<To> volatile;
92};
93
94template<typename To, typename From>
95struct copy_cv<To,From,std::enable_if_t<std::is_const_v<From> && !std::is_volatile_v<From>>> {
96 using type = std::remove_cv_t<To> const;
97};
98
99template<typename To, typename From>
100struct copy_cv<To,From,std::enable_if_t<std::is_const_v<From> && std::is_volatile_v<From>>> {
101 using type = std::remove_cv_t<To> const volatile;
102};
103
104template<typename To, typename From>
105using copy_cv_t = typename copy_cv<To,From>::type;
106
107template<typename T>
109 using type = std::remove_cv_t<std::remove_reference_t<T>>;
110};
111
112template<typename T>
113using remove_cvref_t = typename remove_cvref<T>::type;
114
115template <typename T> struct has_value_type
116{
117 template <typename C> static std::true_type test(typename C::value_type *);
118 template <typename> static std::false_type test(...);
119
120 static const bool value = std::is_same_v<decltype(test<T>(nullptr)), std::true_type>;
121};
122
123template<typename T>
124inline constexpr bool has_value_type_v = has_value_type<T>::value;
125
126template <typename T> struct has_add_callback
127{
128 template <typename C> static std::true_type test(decltype(&C::add_callback) func_ptr);
129 template <typename> static std::false_type test(...);
130
131 static const bool value = std::is_same_v<decltype(test<T>(nullptr)), std::true_type>;
132};
133
134template<typename T>
135inline constexpr bool has_add_callback_v = has_add_callback<T>::value;
136
137template<typename T, typename Enable=void>
139
140template<typename T>
141struct make_value_type<T, std::enable_if_t<!has_value_type_v<T>>> { using type = T; };
142
143template<typename T>
144struct make_value_type<T, std::enable_if_t<has_value_type_v<T>>> { using type = typename T::value_type; };
145
146template<typename T>
147using make_value_type_t = typename make_value_type<T>::type;
148
149}
STL namespace.
Definition type_traits.hpp:9
Definition type_traits.hpp:27
Definition type_traits.hpp:41
Definition type_traits.hpp:49
Definition type_traits.hpp:66
Definition type_traits.hpp:82
Definition type_traits.hpp:108
Definition type_traits.hpp:116
Definition type_traits.hpp:127
Definition type_traits.hpp:138