HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
type_traits.hpp
1// Copyright Take Vos 2019-2021.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include <cstdint>
8#include <type_traits>
9#include <string>
10#include <string_view>
11
12namespace tt {
13
14// clang-format off
15template<typename T> struct is_numeric_integer : std::false_type {};
16template<> struct is_numeric_integer<signed char> : std::true_type {};
17template<> struct is_numeric_integer<unsigned char> : std::true_type {};
18template<> struct is_numeric_integer<signed short> : std::true_type {};
19template<> struct is_numeric_integer<unsigned short> : std::true_type {};
20template<> struct is_numeric_integer<signed int> : std::true_type {};
21template<> struct is_numeric_integer<unsigned int> : std::true_type {};
22template<> struct is_numeric_integer<signed long> : std::true_type {};
23template<> struct is_numeric_integer<unsigned long> : std::true_type {};
24template<> struct is_numeric_integer<signed long long> : std::true_type {};
25template<> struct is_numeric_integer<unsigned long long> : std::true_type {};
26
30template<typename T>
31inline constexpr bool is_numeric_integer_v = is_numeric_integer<T>::value;
32
33template<typename T> struct is_character : std::false_type {};
34template<> struct is_character<char> : std::true_type {};
35template<> struct is_character<wchar_t> : std::true_type {};
36template<> struct is_character<char8_t> : std::true_type {};
37template<> struct is_character<char16_t> : std::true_type {};
38template<> struct is_character<char32_t> : std::true_type {};
39
43template<typename T>
44inline constexpr bool is_character_v = is_character<T>::value;
45
48template<typename T> struct make_string { };
49template<> struct make_string<char> { using type = std::string; };
50template<> struct make_string<wchar_t> { using type = std::wstring; };
51template<> struct make_string<char8_t> { using type = std::u8string; };
52template<> struct make_string<char16_t> { using type = std::u16string; };
53template<> struct make_string<char32_t> { using type = std::u32string; };
54
57template<typename T>
58using make_string_t = typename make_string<T>::type;
59
62template<typename T> struct make_string_view { using type = void; };
63template<> struct make_string_view<char> { using type = std::string_view; };
64template<> struct make_string_view<wchar_t> { using type = std::wstring_view; };
65template<> struct make_string_view<char8_t> { using type = std::u8string_view; };
66template<> struct make_string_view<char16_t> { using type = std::u16string_view; };
67template<> struct make_string_view<char32_t> { using type = std::u32string_view; };
68
71template<typename T>
72using make_string_view_t = typename make_string_view<T>::type;
73
74template<typename T, typename U>
76 using type = decltype(static_cast<T>(0) + static_cast<U>(0));
77};
78
79template<typename T, typename U>
80using make_promote_t = typename make_promote<T,U>::type;
81
82template<typename T, typename Ei=void>
84 using type = uintmax_t;
85};
86
87template<typename T>
88struct make_intmax<T,std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T>>> {
89 using type = uintmax_t;
90};
91
92template<typename T>
93struct make_intmax<T,std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>>> {
94 using type = intmax_t;
95};
96
97template<typename T>
98using make_intmax_t = typename make_intmax<T>::type;
99
102template<typename T> struct make_larger { using type = T; };
103template<> struct make_larger<signed long> { using type = signed long long; };
104template<> struct make_larger<signed int> { using type = signed long; };
105template<> struct make_larger<signed short> { using type = signed int; };
106template<> struct make_larger<signed char> { using type = signed short; };
107template<> struct make_larger<unsigned long> { using type = unsigned long long; };
108template<> struct make_larger<unsigned int> { using type = unsigned long; };
109template<> struct make_larger<unsigned short> { using type = unsigned int; };
110template<> struct make_larger<unsigned char> { using type = unsigned short; };
111template<> struct make_larger<double> { using type = long double; };
112template<> struct make_larger<float> { using type = double; };
113
116template<typename T>
117using make_larger_t = typename make_larger<T>::type;
118
121template<typename To, typename From, typename Ei=void>
122struct copy_cv {};
123
124template<typename To, typename From>
125struct copy_cv<To,From,std::enable_if_t<!std::is_const_v<From> && !std::is_volatile_v<From>>> {
126 using type = std::remove_cv_t<To>;
127};
128
129template<typename To, typename From>
130struct copy_cv<To,From,std::enable_if_t<!std::is_const_v<From> && std::is_volatile_v<From>>> {
131 using type = std::remove_cv_t<To> volatile;
132};
133
134template<typename To, typename From>
135struct copy_cv<To,From,std::enable_if_t<std::is_const_v<From> && !std::is_volatile_v<From>>> {
136 using type = std::remove_cv_t<To> const;
137};
138
139template<typename To, typename From>
140struct copy_cv<To,From,std::enable_if_t<std::is_const_v<From> && std::is_volatile_v<From>>> {
141 using type = std::remove_cv_t<To> const volatile;
142};
143
146template<typename To, typename From>
147using copy_cv_t = typename copy_cv<To,From>::type;
148
149template <typename T> struct has_value_type
150{
151 template <typename C> static std::true_type test(typename C::value_type *);
152 template <typename> static std::false_type test(...);
153
154 static const bool value = std::is_same_v<decltype(test<T>(nullptr)), std::true_type>;
155};
156
157template<typename T>
158inline constexpr bool has_value_type_v = has_value_type<T>::value;
159
160template <typename T> struct has_add_callback
161{
162 template <typename C> static std::true_type test(decltype(&C::add_callback) func_ptr);
163 template <typename> static std::false_type test(...);
164
165 static const bool value = std::is_same_v<decltype(test<T>(nullptr)), std::true_type>;
166};
167
168template<typename T>
169inline constexpr bool has_add_callback_v = has_add_callback<T>::value;
170
171template<typename BaseType, typename DerivedType>
172struct is_decayed_base_of : public std::is_base_of<std::decay_t<BaseType>,std::decay_t<DerivedType>> {};
173
174template<typename BaseType, typename DerivedType>
175constexpr bool is_decayed_base_of_v = is_decayed_base_of<BaseType,DerivedType>::value;
176
177template<typename DerivedType, typename BaseType>
178struct is_derived_from : public std::is_base_of<BaseType,DerivedType> {};
179
180template<typename DerivedType, typename BaseType>
181constexpr bool is_derived_from_v = is_derived_from<DerivedType,BaseType>::value;
182
183template<typename DerivedType, typename BaseType>
184struct is_decayed_derived_from : public is_decayed_base_of<BaseType,DerivedType> {};
185
186template<typename DerivedType, typename BaseType>
187constexpr bool is_decayed_derived_from_v = is_decayed_derived_from<DerivedType,BaseType>::value;
188
189template<typename T1, typename T2>
190constexpr bool is_different_v = !std::is_same_v<T1,T2>;
191
192
193template<typename First, typename Second>
194struct use_first {
195 using type = First;
196};
197
198template<typename First, typename Second>
200
201}
STL namespace.
Definition type_traits.hpp:15
Definition type_traits.hpp:33
type-trait to convert a character to a string type.
Definition type_traits.hpp:48
type-trait to convert a character to a string_view type.
Definition type_traits.hpp:62
Definition type_traits.hpp:75
Definition type_traits.hpp:83
Type-trait to increase the size of an integral type.
Definition type_traits.hpp:102
Type-trait to copy const volitile qualifiers from one type to another.
Definition type_traits.hpp:122
Definition type_traits.hpp:150
Definition type_traits.hpp:161
Definition type_traits.hpp:172
Definition type_traits.hpp:178
Definition type_traits.hpp:184
Definition type_traits.hpp:194