16 #ifndef INCLUDE_NN_NLIB_TYPETRAITS_H_ 17 #define INCLUDE_NN_NLIB_TYPETRAITS_H_ 21 #ifndef NLIB_HAS_NATIVE_TYPETRAITS 24 #include <type_traits> 30 template<
class T, T v>
31 struct IntegralConstant {
32 static const T value = v;
34 typedef IntegralConstant type;
35 operator value_type()
const {
return value; }
39 typedef IntegralConstant<bool, true> TrueType;
40 typedef IntegralConstant<bool, false> FalseType;
42 #define NLIB_DEF_TRUETYPE(name, tp) \ 45 typedef TrueType type; \ 55 template<
class T1,
class T2>
58 struct my_or2<TrueType, T> {
59 typedef TrueType type;
62 struct my_or2<FalseType, T> {
63 typedef typename my_or1<T>::type type;
66 template<
class T1,
class T2,
class T3>
68 template<
class T1,
class T2>
69 struct my_or3<TrueType, T1, T2> {
70 typedef TrueType type;
72 template<
class T1,
class T2>
73 struct my_or3<FalseType, T1, T2> {
74 typedef typename my_or2<T1, T2>::type type;
77 template<
class T1,
class T2,
class T3,
class T4>
79 template<
class T1,
class T2,
class T3>
80 struct my_or4<TrueType, T1, T2, T3> {
81 typedef TrueType type;
83 template<
class T1,
class T2,
class T3>
84 struct my_or4<FalseType, T1, T2, T3> {
85 typedef typename my_or3<T1, T2, T3>::type type;
88 template<
class T1 = FalseType,
class T2 = FalseType,
class T3 = FalseType,
class T4 = FalseType>
90 typedef typename my_or4<T1, T2, T3, T4>::type type;
96 template<
bool B,
class T =
void>
99 struct EnableIf<true, T> {
104 template<
bool B,
class T,
class F>
108 template<
class T,
class F>
109 struct Conditional<false, T, F> {
119 struct RemoveConst<const T> {
124 struct RemoveVolatile {
128 struct RemoveVolatile<volatile T> {
134 typedef typename RemoveVolatile<typename RemoveConst<T>::type>::type type;
143 struct RemovePtr<T*> {
147 struct RemovePtr<const T*> {
151 struct RemovePtr<volatile T*> {
155 struct RemovePtr<const volatile T*> {
165 struct RemoveRef<T&> {
174 struct AddRef<void> {
179 template<
class T1,
class T2>
180 struct IsSame :
public FalseType {};
182 struct IsSame<T, T> :
public TrueType {};
185 namespace tt_detail {
188 typedef FalseType type;
190 NLIB_DEF_TRUETYPE(is_void,
void);
194 struct IsVoid :
public tt_detail::is_void<typename RemoveCv<T>::type>::type {};
197 namespace tt_detail {
200 struct is_integral_ex {
201 typedef FalseType type;
203 NLIB_DEF_TRUETYPE(is_integral_ex,
signed char);
204 NLIB_DEF_TRUETYPE(is_integral_ex,
signed short);
205 NLIB_DEF_TRUETYPE(is_integral_ex,
signed int);
206 NLIB_DEF_TRUETYPE(is_integral_ex,
signed long);
207 NLIB_DEF_TRUETYPE(is_integral_ex,
signed long long);
211 typedef FalseType type;
213 NLIB_DEF_TRUETYPE(is_integral,
bool);
214 NLIB_DEF_TRUETYPE(is_integral,
char);
215 NLIB_DEF_TRUETYPE(is_integral,
wchar_t);
216 NLIB_DEF_TRUETYPE(is_integral,
short);
217 NLIB_DEF_TRUETYPE(is_integral,
int);
218 NLIB_DEF_TRUETYPE(is_integral,
long);
219 NLIB_DEF_TRUETYPE(is_integral,
long long);
221 NLIB_DEF_TRUETYPE(is_integral,
unsigned char);
222 NLIB_DEF_TRUETYPE(is_integral,
unsigned short);
223 NLIB_DEF_TRUETYPE(is_integral,
unsigned int);
224 NLIB_DEF_TRUETYPE(is_integral,
unsigned long long);
225 NLIB_DEF_TRUETYPE(is_integral,
unsigned long);
230 :
public tt_detail::my_or<
231 typename tt_detail::is_integral<typename RemoveCv<T>::type>::type,
232 typename tt_detail::is_integral_ex<typename RemoveCv<T>::type>::type>::type {};
235 namespace tt_detail {
238 struct is_signed_ex {
239 typedef FalseType type;
241 NLIB_DEF_TRUETYPE(is_signed_ex,
signed char);
242 NLIB_DEF_TRUETYPE(is_signed_ex,
signed short);
243 NLIB_DEF_TRUETYPE(is_signed_ex,
signed int);
244 NLIB_DEF_TRUETYPE(is_signed_ex,
signed long);
245 NLIB_DEF_TRUETYPE(is_signed_ex,
signed long long);
249 typedef FalseType type;
251 NLIB_DEF_TRUETYPE(is_signed,
char);
252 NLIB_DEF_TRUETYPE(is_signed,
short);
253 NLIB_DEF_TRUETYPE(is_signed,
int);
254 NLIB_DEF_TRUETYPE(is_signed,
long);
255 NLIB_DEF_TRUETYPE(is_signed,
long long);
256 NLIB_DEF_TRUETYPE(is_signed,
float);
257 NLIB_DEF_TRUETYPE(is_signed,
double);
261 struct IsSigned :
public tt_detail::my_or<
262 typename tt_detail::is_signed<typename RemoveCv<T>::type>::type,
263 typename tt_detail::is_signed_ex<typename RemoveCv<T>::type>::type>::type {};
267 typedef FalseType type;
270 struct IsUnsigned<bool> {
271 typedef TrueType type;
274 struct IsUnsigned<wchar_t> {
275 typedef TrueType type;
278 struct IsUnsigned<unsigned char> {
279 typedef TrueType type;
282 struct IsUnsigned<unsigned short> {
283 typedef TrueType type;
286 struct IsUnsigned<unsigned int> {
287 typedef TrueType type;
290 struct IsUnsigned<unsigned long> {
291 typedef TrueType type;
294 struct IsUnsigned<unsigned long long> {
295 typedef TrueType type;
299 namespace tt_detail {
302 struct is_floating_point {
303 typedef FalseType type;
305 NLIB_DEF_TRUETYPE(is_floating_point,
float);
306 NLIB_DEF_TRUETYPE(is_floating_point,
double);
307 NLIB_DEF_TRUETYPE(is_floating_point,
long double);
312 struct IsFloatingPoint :
public tt_detail::is_floating_point<typename RemoveCv<T>::type>::type {};
317 :
public IntegralConstant<bool, IsIntegral<T>::value || IsFloatingPoint<T>::value> {};
320 namespace tt_detail {
322 struct IsPointerHelper :
public FalseType {};
324 struct IsPointerHelper<T*> :
public TrueType {};
327 struct IsPointer :
public tt_detail::IsPointerHelper<typename RemoveCv<T>::type> {};
331 struct IsReference :
public FalseType {};
333 struct IsReference<T&> :
public TrueType {};
337 struct IsArray :
public FalseType {};
339 struct IsArray<T[]> :
public TrueType {};
340 template<
class T,
size_t N>
341 struct IsArray<T[N]> :
public TrueType {};
344 namespace tt_detail {
346 struct is_member_pointer :
public FalseType {};
347 template<
class T,
class U>
348 struct is_member_pointer<T U::*> :
public TrueType {};
351 struct IsMemberPointer :
public tt_detail::is_member_pointer<typename RemoveCv<T>::type> {};
354 namespace tt_detail {
356 struct is_function_ {
357 typedef FalseType type;
360 struct is_function_<true> {
361 typedef TrueType type;
371 static One test(...);
373 static Two test(U (*)[1]);
377 #pragma diag_suppress 1931 379 typedef typename is_function_<sizeof(test<T>(0)) == 1>::type type;
381 #pragma diag_warning 1931 385 struct is_function<T&> {
386 typedef FalseType type;
389 struct is_function<void> {
390 typedef FalseType type;
393 struct is_function<const void> {
394 typedef FalseType type;
397 struct is_function<volatile void> {
398 typedef FalseType type;
401 struct is_function<const volatile void> {
402 typedef FalseType type;
406 struct IsFunction :
public tt_detail::is_function<T>::type {};
408 #if !defined(NN_PLATFORM_CTR) 410 struct IsEnum :
public IntegralConstant<bool, __is_enum(T)> {};
413 namespace tt_detail {
414 typedef char (&SizeOverOne)[2];
415 template<class T, bool convert_possible = !IsArithmetic<T>::value && !IsReference<T>::value &&
416 !IsPointer<T>::value && !IsMemberPointer<T>::value &&
417 !IsFunction<T>::value && !IsVoid<T>::value &&
423 struct ConsumeUDC<T, false> {
424 operator SizeOverOne()
const;
426 char enum_check(
bool x);
427 char enum_check(
char x);
428 char enum_check(
signed char x);
429 char enum_check(
unsigned char x);
430 char enum_check(
wchar_t x);
431 char enum_check(
signed short x);
432 char enum_check(
unsigned short x);
433 char enum_check(
signed int x);
434 char enum_check(
unsigned int x);
435 char enum_check(
signed long x);
436 char enum_check(
unsigned long x);
437 char enum_check(
signed long long x);
438 char enum_check(
unsigned long long x);
439 char enum_check(
float x);
440 char enum_check(
double x);
441 char enum_check(
long double x);
442 SizeOverOne enum_check(SizeOverOne x);
443 SizeOverOne enum_check(...);
446 enum { value =
sizeof(enum_check(ConsumeUDC<T>())) == 1 };
451 struct IsEnum :
public IntegralConstant<bool, tt_detail::is_enum<T>::value> {};
454 #if !defined(NN_PLATFORM_CTR) && !defined(CAFE) 457 :
public IntegralConstant<bool, __is_pod(T) || IsEnum<T>::value || IsArithmetic<T>::value ||
458 IsPointer<T>::value || IsMemberPointer<T>::value> {};
461 struct IsTriviallyDestructible :
public IntegralConstant<bool, __has_trivial_destructor(T)> {};
464 struct IsTriviallyDefaultConstructible
465 :
public IntegralConstant<bool, __has_trivial_default_constructor(T)> {};
468 struct IsTriviallyDefaultConstructible
469 :
public IntegralConstant<bool, std::has_trivial_default_constructor<T>::value> {};
474 namespace tt_detail {
478 :
public tt_detail::my_or<typename IsArithmetic<T>::type, typename IsPointer<T>::type,
479 typename IsMemberPointer<T>::type, typename IsEnum<T>::type>::type {};
483 typedef typename is_pod<typename RemoveCv<T>::type>::type type;
485 template<
class T,
size_t N>
486 struct is_pod<T[N]> {
487 typedef typename is_pod<typename RemoveCv<T>::type>::type type;
500 struct IsTriviallyDestructible :
public tt_detail::is_pod<typename RemoveCv<T>::type>::type {};
502 struct IsTriviallyDefaultConstructible
503 :
public tt_detail::is_pod<typename RemoveCv<T>::type>::type {};
506 struct IsPod :
public IsTriviallyDestructible<T> {};
509 #if !defined(NN_PLATFORM_CTR) 511 struct IsEmpty :
public IntegralConstant<bool, __is_empty(T)> {};
514 namespace tt_detail {
516 struct IsEmptyHelper1 :
public T {
523 struct IsEmptyHelper2 {
529 struct IsEmpty :
public IntegralConstant<bool, sizeof(tt_detail::IsEmptyHelper1<T>) ==
530 sizeof(tt_detail::IsEmptyHelper2)> {};
533 #if !defined(NN_PLATFORM_CTR) 535 struct IsClass :
public IntegralConstant<bool, __is_class(T)> {};
546 static yes check(
void (X::*)(
void));
548 static no check(...);
551 static const bool value =
sizeof(check<T>(NULL)) ==
sizeof(yes);
560 #undef NLIB_DEF_TRUETYPE 563 #include <type_traits> 567 #ifdef NLIB_HAS_TR1_TYPETRAITS 568 #define NLIB_DEF_REDIRECT(nlibstruct, stdstruct) \ 571 struct nlibstruct : public std::tr1::stdstruct<T> {} 572 template<
class T, T v>
573 struct IntegralConstant :
public std::tr1::integral_constant<T, v> {};
574 typedef std::tr1::true_type TrueType;
575 typedef std::tr1::false_type FalseType;
576 template<
bool B,
class T =
void>
579 struct EnableIf<true, T> {
582 template<
bool B,
class T,
class F>
586 template<
class T,
class F>
587 struct Conditional<false, T, F> {
590 template<
class T1,
class T2>
591 struct IsSame :
public std::tr1::is_same<T1, T2> {};
593 NLIB_DEF_REDIRECT(IsTriviallyDestructible, has_trivial_destructor);
594 NLIB_DEF_REDIRECT(IsTriviallyDefaultConstructible, has_trivial_default_constructor);
597 #define NLIB_DEF_REDIRECT(nlibstruct, stdstruct) \ 600 struct nlibstruct : public std::stdstruct<T> {} 601 template<
class T, T v>
602 struct IntegralConstant :
public std::integral_constant<T, v> {};
603 typedef std::true_type TrueType;
604 typedef std::false_type FalseType;
605 template<
bool B,
class T>
606 struct EnableIf :
public std::enable_if<B, T> {};
607 template<
bool B,
class T,
class F>
608 struct Conditional :
public std::conditional<B, T, F> {};
609 template<
class T1,
class T2>
610 struct IsSame :
public std::is_same<T1, T2> {};
614 #if defined(__GLIBCXX__) 616 struct IsTriviallyDestructible :
public IntegralConstant<bool, __has_trivial_destructor(T)> {};
618 struct IsTriviallyDefaultConstructible
619 :
public IntegralConstant<bool, __has_trivial_constructor(T)> {};
621 NLIB_DEF_REDIRECT(IsTriviallyDestructible, is_trivially_destructible);
622 NLIB_DEF_REDIRECT(IsTriviallyDefaultConstructible, is_trivially_constructible);
627 NLIB_DEF_REDIRECT(RemoveConst, remove_const);
628 NLIB_DEF_REDIRECT(RemoveVolatile, remove_volatile);
629 NLIB_DEF_REDIRECT(RemovePtr, remove_pointer);
630 NLIB_DEF_REDIRECT(RemoveRef, remove_reference);
631 NLIB_DEF_REDIRECT(AddRef, add_lvalue_reference);
632 NLIB_DEF_REDIRECT(RemoveCv, remove_cv);
633 NLIB_DEF_REDIRECT(IsVoid, is_void);
634 NLIB_DEF_REDIRECT(IsIntegral, is_integral);
635 NLIB_DEF_REDIRECT(IsSigned, is_signed);
636 NLIB_DEF_REDIRECT(IsUnsigned, is_unsigned);
637 NLIB_DEF_REDIRECT(IsFloatingPoint, is_floating_point);
638 NLIB_DEF_REDIRECT(IsArithmetic, is_arithmetic);
639 NLIB_DEF_REDIRECT(IsPointer, is_pointer);
640 NLIB_DEF_REDIRECT(IsReference, is_reference);
641 NLIB_DEF_REDIRECT(IsArray, is_array);
642 NLIB_DEF_REDIRECT(IsMemberPointer, is_member_pointer);
643 NLIB_DEF_REDIRECT(IsFunction, is_function);
644 NLIB_DEF_REDIRECT(IsEnum, is_enum);
646 NLIB_DEF_REDIRECT(IsPod, is_pod);
647 NLIB_DEF_REDIRECT(IsEmpty, is_empty);
648 NLIB_DEF_REDIRECT(IsClass, is_class);
652 #undef NLIB_DEF_REDIRECT 657 #if (defined(_MSVC_LANG) && _MSVC_LANG > 201402L) || __cplusplus >= 201703L 659 using IsSwappable = std::is_swappable<T>;
660 #elif defined(NLIB_HAS_NATIVE_TYPETRAITS) && defined(_MSC_VER) 665 struct can_call_swap_impl {
667 static auto check(
int)
668 -> decltype(swap(std::declval<T&>(), std::declval<T&>()), std::true_type());
670 static std::false_type check(...);
671 using type = decltype(check<T>(0));
674 struct can_call_swap : can_call_swap_impl<T>::type {};
681 struct would_call_std_swap_impl {
683 static auto check(
int) -> std::integral_constant<
684 bool, std::is_same<decltype(swap(std::declval<U&>(), std::declval<U&>())), tag>::value>;
686 static std::false_type check(...);
687 using type = decltype(check<T>(0));
690 struct would_call_std_swap : would_call_std_swap_impl<T>::type {};
693 struct IsSwappable : std::integral_constant<bool, detail::can_call_swap<T>::value &&
694 (!detail2::would_call_std_swap<T>::value ||
695 (std::is_move_assignable<T>::value &&
696 std::is_move_constructible<T>::value))> {};
697 template<
typename T,
size_t N>
698 struct IsSwappable<T[N]> : IsSwappable<T> {};
709 template<
class X, T& (X::*Func)(T&, move_tag)>
712 static yes check(helper<X, &X::assign>* p);
714 static no check(...);
718 #pragma diag_suppress 1931 720 static const bool value =
sizeof(check<T>(NULL)) ==
sizeof(yes);
722 #pragma diag_warning 1931 726 template<
class T,
bool isClass>
727 struct IsSwappable_ :
public IntegralConstant<bool, detail::HasSwapMemFn<T>::value> {};
730 struct IsSwappable_<T, false>
731 :
public IntegralConstant<bool, IsArithmetic<T>::value || IsPointer<T>::value ||
732 IsFunction<T>::value || IsMemberPointer<T>::value ||
733 IsEnum<T>::value> {};
741 struct IsSwappable :
public detail::IsSwappable_<T, IsClass<T>::value> {};
746 #endif // INCLUDE_NN_NLIB_TYPETRAITS_H_ #define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
A file that contains the configuration information for each development environment.