From 48c1f301a02628a363410dfd5a23b5e4e2bfa3e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Mon, 2 Jan 2023 20:28:30 -0800 Subject: [PATCH] Provide type trait struct for use in template arguments to make MSVC happy. --- include/bx/inline/typetraits.inl | 200 ++++++++++++++++++++++--------- 1 file changed, 142 insertions(+), 58 deletions(-) diff --git a/include/bx/inline/typetraits.inl b/include/bx/inline/typetraits.inl index 3af6a0514..c1ecb404f 100644 --- a/include/bx/inline/typetraits.inl +++ b/include/bx/inline/typetraits.inl @@ -114,7 +114,6 @@ namespace bx template using RemoveVolatileType = typename RemoveVolatileT::Type; //--- - template struct IsBoundedArrayT : FalseConstant {}; template struct IsBoundedArrayT : TrueConstant {}; @@ -124,6 +123,7 @@ namespace bx return IsBoundedArrayT::value; } + //--- template struct IsUnboundedArrayT : FalseConstant {}; template struct IsUnboundedArrayT : TrueConstant {}; @@ -133,194 +133,255 @@ namespace bx return IsUnboundedArrayT::value; } + //--- + template struct IsArrayT : public BoolConstantT::value + || IsUnboundedArrayT::value + > {}; + template inline constexpr bool isArray() { - return isBoundedArray() - || isUnboundedArray() - ; + return IsArrayT::value; } + //--- + template struct IsEnumT : public BoolConstantT<__is_enum(Ty)> {}; + template inline constexpr bool isEnum() { - return !!__is_enum(Ty); + return IsEnumT::value; } + //--- + template struct IsUnionT : public BoolConstantT<__is_union(Ty)> {}; + template inline constexpr bool isUnion() { - return !!__is_union(Ty); + return IsUnionT::value; } + //--- + template struct IsAbstractT : public BoolConstantT<__is_abstract(Ty)> {}; + template inline constexpr bool isAbstract() { - return !!__is_abstract(Ty); + return IsAbstractT::value; } + //--- + template struct IsAggregateT : public BoolConstantT<__is_aggregate(Ty)> {}; + template inline constexpr bool isAggregate() { - return !!__is_aggregate(Ty); + return IsAggregateT::value; } + //--- + template struct IsBaseOfT : public BoolConstantT<__is_base_of(BaseT, DerivedT)> {}; + template inline constexpr bool isBaseOf() { - return !!__is_base_of(BaseT, DerivedT); + return IsBaseOfT::value; } + //--- + template struct IsPolymorphicT : public BoolConstantT<__is_polymorphic(Ty)> {}; + template inline constexpr bool isPolymorphic() { - return !!__is_polymorphic(Ty); + return IsPolymorphicT::value; } + //--- + template struct IsDestructorVirtualT : public BoolConstantT<__has_virtual_destructor(Ty)> {}; + template inline constexpr bool isDestructorVirtual() { - return __has_virtual_destructor(Ty); + return IsDestructorVirtualT::value; } + //--- + template struct IsClassT : public BoolConstantT<__is_class(Ty)> {}; + template inline constexpr bool isClass() { - return !!__is_class(Ty); + return IsClassT::value; } + //--- + template struct IsFinalT : public BoolConstantT<__is_final(Ty)> {}; + template inline constexpr bool isFinal() { - return !!__is_final(Ty); + return IsFinalT::value; } + //--- + template struct IsEmptyT : public BoolConstantT<__is_empty(Ty)> {}; + template inline constexpr bool isEmpty() { - return !!__is_empty(Ty); + return IsEmptyT::value; } + //--- + template struct IsStandardLayoutT : public BoolConstantT<__is_standard_layout(Ty)> {}; + template inline constexpr bool isStandardLayout() { - return !!__is_standard_layout(Ty); + return IsStandardLayoutT::value; } + //--- + template struct IsTrivialT : public BoolConstantT<__is_trivial(Ty)> {}; + template inline constexpr bool isTrivial() { - return !!__is_trivial(Ty); + return IsTrivialT::value; } + //--- + template struct IsPodT : public BoolConstantT::value + && IsTrivialT::value + > {}; + template inline constexpr bool isPod() { - return isStandardLayout() - && isTrivial() - ; + return IsPodT::value; } + //--- + template struct IsAssignableT : public BoolConstantT<__is_assignable(Ty, FromT)> {}; + template struct IsCopyAssignableT : public IsAssignableT, AddRvalueReferenceType> {}; + template struct IsMoveAssignableT : public IsAssignableT, AddRvalueReferenceType> {}; + template inline constexpr bool isAssignable() { - return !!__is_assignable(Ty, FromT); + return IsAssignableT::value; } template inline constexpr bool isCopyAssignable() { - return isAssignable< - AddLvalueReferenceType - , AddLvalueReferenceType - >(); + return IsCopyAssignableT::value; } template inline constexpr bool isMoveAssignable() { - return isAssignable< - AddLvalueReferenceType - , AddRvalueReferenceType - >(); + return IsMoveAssignableT::value; } + //--- + template struct IsTriviallyAssignableT : public BoolConstantT<__is_trivially_assignable(Ty, FromT)> {}; + template struct IsTriviallyCopyAssignableT : public IsTriviallyAssignableT, AddRvalueReferenceType> {}; + template struct IsTriviallyMoveAssignableT : public IsTriviallyAssignableT, AddRvalueReferenceType> {}; + template inline constexpr bool isTriviallyAssignable() { - return !!__is_trivially_assignable(Ty, FromT); + return IsTriviallyAssignableT::value; } template inline constexpr bool isTriviallyCopyAssignable() { - return isTriviallyAssignable< - AddLvalueReferenceType - , AddRvalueReferenceType - >(); + return IsTriviallyCopyAssignableT::value; } template inline constexpr bool isTriviallyMoveAssignable() { - return isTriviallyAssignable< - AddLvalueReferenceType - , AddRvalueReferenceType - >(); + return IsTriviallyMoveAssignableT::value; } + //--- + template struct IsConstructibleT : public BoolConstantT<__is_constructible(Ty, ArgsT...)> {}; + template struct IsCopyConstructibleT : public IsConstructibleT> {}; + template struct IsMoveConstructibleT : public IsConstructibleT> {}; + template inline constexpr bool isConstructible() { - return !!__is_constructible(Ty, ArgsT...); + return IsConstructibleT::value; } template inline constexpr bool isCopyConstructible() { - return isConstructible>(); + return IsCopyConstructibleT::value; } template inline constexpr bool isMoveConstructible() { - return isConstructible>(); + return IsMoveConstructibleT::value; } + //--- + template struct IsTriviallyConstructibleT : public BoolConstantT<__is_trivially_constructible(Ty, ArgsT...)> {}; + template struct IsTriviallyCopyConstructibleT : public IsTriviallyConstructibleT> {}; + template struct IsTriviallyMoveConstructibleT : public IsTriviallyConstructibleT> {}; + template - inline constexpr bool isTriviallyConstructible() + constexpr bool isTriviallyConstructible() { - return !!__is_trivially_constructible(Ty, ArgsT...); + return IsTriviallyConstructibleT::value; } template inline constexpr bool isTriviallyCopyConstructible() { - return isTriviallyConstructible>(); + return IsTriviallyCopyConstructibleT::value; } template inline constexpr bool isTriviallyMoveConstructible() { - return isTriviallyConstructible>(); + return IsTriviallyMoveConstructibleT::value; } + //--- + template struct IsTriviallyCopyableT : public BoolConstantT<__is_trivially_copyable(Ty)> {}; + template inline constexpr bool isTriviallyCopyable() { - return !!__is_trivially_copyable(Ty); + return IsTriviallyCopyableT::value; } - template - inline constexpr bool isTriviallyDestructible() - { + //--- + template struct IsTriviallyDestructibleT : public BoolConstantT< #if BX_COMPILER_GCC - return !!__has_trivial_destructor(Ty); + __has_trivial_destructor(Ty) #else - return !!__is_trivially_destructible(Ty); + __is_trivially_destructible(Ty) #endif // BX_COMPILER_GCC + > {}; + + template + inline constexpr bool isTriviallyDestructible() + { + return IsTriviallyDestructibleT::value; } + //--- template struct IsConstT : FalseConstant {}; template struct IsConstT : TrueConstant {}; @@ -330,6 +391,7 @@ namespace bx return IsConstT::value; } + //--- template struct IsVolatileT : FalseConstant {}; template struct IsVolatileT : TrueConstant {}; @@ -339,6 +401,7 @@ namespace bx return IsVolatileT::value; } + //--- template struct IsLvalueReferenceT : FalseConstant {}; template struct IsLvalueReferenceT : TrueConstant {}; @@ -348,6 +411,7 @@ namespace bx return IsLvalueReferenceT::value; } + //--- template struct IsRvalueReferenceT : FalseConstant {}; template struct IsRvalueReferenceT : TrueConstant {}; @@ -357,14 +421,19 @@ namespace bx return IsRvalueReferenceT::value; } + //--- + template struct IsReferenceT : public BoolConstantT::value + || IsRvalueReferenceT::value + > {}; + template inline constexpr bool isReference() { - return isLvalueReference() - || isRvalueReference() - ; + return IsReferenceT::value; } + //--- template struct IsPointerT : FalseConstant {}; template struct IsPointerT : TrueConstant {}; template struct IsPointerT : TrueConstant {}; @@ -377,18 +446,25 @@ namespace bx return IsPointerT::value; } + //--- + template struct IsSignedT : public BoolConstantT {}; + template inline constexpr bool isSigned() { - return Ty(-1) < Ty(0); + return IsSignedT::value; } + //--- + template struct IsUnsignedT : public BoolConstantT {}; + template inline constexpr bool isUnsigned() { - return Ty(-1) > Ty(0); + return IsUnsignedT::value; } + //--- template struct IsIntegerT : FalseConstant {}; template<> struct IsIntegerT : TrueConstant {}; template<> struct IsIntegerT : TrueConstant {}; @@ -412,6 +488,7 @@ namespace bx return IsIntegerT::value; } + //--- template struct IsFloatingPointT : FalseConstant {}; template<> struct IsFloatingPointT : TrueConstant {}; template<> struct IsFloatingPointT< double> : TrueConstant {}; @@ -423,14 +500,20 @@ namespace bx return IsFloatingPointT::value; } + //--- + template struct IsArithmeticT : BoolConstantT::value + || IsFloatingPointT::value + > + {}; + template inline constexpr bool isArithmetic() { - return isInteger() - || isFloatingPoint() - ; + return IsArithmeticT::value; } + //--- template struct IsSameT : FalseConstant {}; template struct IsSameT : TrueConstant {}; @@ -440,6 +523,7 @@ namespace bx return IsSameT::value; } + //--- template inline constexpr RemoveReferenceType&& move(Ty&& _a) {