5#ifndef OSCR_SPECIALIZATIONS_H_
6# define OSCR_SPECIALIZATIONS_H_
11# include "common/Types.h"
13#define __spec_def(NAME, ...) template<__VA_ARGS__> struct NAME
14#define __spec_cond(NAME, ...) template<> struct NAME<__VA_ARGS__>
15#define __spec_template(...) template<__VA_ARGS__> struct
16#define __spec_enabled public enable_spec {}
17#define __spec_disabled public disable_spec {}
19#define __spec_v(NAME) template <class T> inline constexpr bool NAME ## _v = NAME ## <T>::value;
35 struct enable_if<true, T>
40 template <
bool B,
class T =
void >
41 using enable_if_t =
typename enable_if<B, T>::type;
50 template <
class T, T v>
53 static const T value = v;
56 typedef __spec_result<bool, true> enable_spec;
57 typedef __spec_result<bool, false> disable_spec;
60 using spec_result = __spec_result<bool, v>;
61 typedef spec_result<true> enable_spec;
62 typedef spec_result<false> disable_spec;
64 template<
class T, T v>
65 struct integral_constant
67 static constexpr T value = v;
69 using type = integral_constant;
70 constexpr operator value_type() const noexcept {
return value; }
71 constexpr value_type operator()() const noexcept {
return value; }
74 using true_type = integral_constant<bool, true>;
75 using false_type = integral_constant<bool, false>;
80 true_type test(
int T::*);
87 struct is_class : decltype(detail::test<T>(nullptr)) {};
92 true_type test_ptr_conv(
const volatile B*);
95 false_type test_ptr_conv(
const volatile void*);
97 template<
typename,
typename>
98 auto test_is_base_of(...) -> true_type;
100 template<
typename B,
typename D>
101 auto test_is_base_of(
int) ->
decltype(test_ptr_conv<B>(
static_cast<D *
>(
nullptr)));
104 template <
typename Base,
typename Derived>
105 struct is_base_of : integral_constant<
107 is_class<Base>::value &&
108 is_class<Derived>::value &&
109 decltype(details::test_is_base_of<Base, Derived>(0))::value
112 template <
class Base,
class Derived>
113 inline constexpr bool is_base_of_v = is_base_of<Base, Derived>::value;
117 template <
template <
typename...>
class base,
typename derived>
118 struct is_base_of_template_impl
120 template<
typename... Ts>
121 static constexpr true_type test(
const base<Ts...> *);
122 static constexpr false_type test(...);
123 using type =
decltype(test(declval<derived*>()));
126 template <
template <
typename...>
class base,
typename derived>
127 using is_base_of_template =
typename is_base_of_template_impl<base, derived>::type;
133 template<
class T,
class U>
134 struct is_same: __spec_disabled;
137 struct is_same<T, T>: __spec_enabled;
139 template <class T, class U>
140 inline constexpr bool is_same_v = is_same<T, U>::value;
146 TRAIT_DEF(is_int32, typename T);
147 TRAIT_COND(is_int32, int32_t);
148 TRAIT_HELPERS(is_int32);
154 TRAIT_DEF(is_integer, typename T);
155 TRAIT_COND(is_integer, int8_t);
156 TRAIT_COND(is_integer, uint8_t);
157 TRAIT_COND(is_integer, int16_t);
158 TRAIT_COND(is_integer, uint16_t);
159 TRAIT_COND(is_integer, int32_t);
160 TRAIT_COND(is_integer, uint32_t);
161 TRAIT_HELPERS(is_integer);
168 TRAIT_DEF(is_signed, typename T);
169 TRAIT_COND(is_signed, int8_t);
170 TRAIT_COND(is_signed, int16_t);
171 TRAIT_COND(is_signed, int32_t);
172 TRAIT_HELPERS(is_signed);
175 TRAIT_DEF(is_unsigned, typename T);
176 TRAIT_COND(is_unsigned, uint8_t);
177 TRAIT_COND(is_unsigned, uint16_t);
178 TRAIT_COND(is_unsigned, uint32_t);
179 TRAIT_HELPERS(is_unsigned);
182 TRAIT_DEF(is_number, typename T);
183 TRAIT_COND(is_number, int8_t);
184 TRAIT_COND(is_number, uint8_t);
185 TRAIT_COND(is_number, int16_t);
186 TRAIT_COND(is_number, uint16_t);
187 TRAIT_COND(is_number, int32_t);
188 TRAIT_COND(is_number, uint32_t);
189 TRAIT_COND(is_number, double);
190 TRAIT_HELPERS(is_number);
193 TRAIT_DEF(is_any_number, typename T);
194 TRAIT_COND(is_any_number, int8_t);
195 TRAIT_COND(is_any_number, uint8_t);
196 TRAIT_COND(is_any_number, int16_t);
197 TRAIT_COND(is_any_number, uint16_t);
198 TRAIT_COND(is_any_number, int32_t);
199 TRAIT_COND(is_any_number, uint32_t);
200 TRAIT_COND(is_any_number, int64_t);
201 TRAIT_COND(is_any_number, uint64_t);
202 TRAIT_COND(is_any_number, double);
203 TRAIT_HELPERS(is_any_number);
206 TRAIT_DEF(is_any_signed, typename T);
207 TRAIT_COND(is_any_signed, int8_t);
208 TRAIT_COND(is_any_signed, int16_t);
209 TRAIT_COND(is_any_signed, int32_t);
210 TRAIT_COND(is_any_signed, int64_t);
211 TRAIT_HELPERS(is_any_signed);
214 TRAIT_DEF(is_any_unsigned, typename T);
215 TRAIT_COND(is_any_unsigned, uint8_t);
216 TRAIT_COND(is_any_unsigned, uint16_t);
217 TRAIT_COND(is_any_unsigned, uint32_t);
218 TRAIT_COND(is_any_unsigned, uint64_t);
219 TRAIT_HELPERS(is_any_unsigned);
222 CONV_DEF(make_signed, if_is_any_number_t<T> Enable = true);
223 CONV_TYPE(make_signed, int8_t, uint8_t, true);
224 CONV_TYPE(make_signed, int16_t, uint16_t, true);
225 CONV_TYPE(make_signed, int32_t, uint32_t, true);
226 CONV_TYPE(make_signed, int64_t, uint64_t, true);
227 CONV_HELPER(make_signed);
230 CONV_DEF(make_unsigned, if_is_any_number_t<T> Enable = true);
231 CONV_TYPE(make_unsigned, uint8_t, int8_t, true);
232 CONV_TYPE(make_unsigned, uint16_t, int16_t, true);
233 CONV_TYPE(make_unsigned, uint32_t, int32_t, true);
234 CONV_TYPE(make_unsigned, uint64_t, int64_t, true);
235 CONV_HELPER(make_unsigned);
240 static bool const value =
false;
244 struct is_format<OSCR::Serial::Style>
246 static bool const value =
true;
250 struct is_format<OSCR::Serial::Foreground>
252 static bool const value =
true;
256 struct is_format<OSCR::Serial::Background>
258 static bool const value =
true;
264 static bool const value =
false;
Utility methods.
Definition Util.h:18
Main program.
Definition Storage.h:13