From 38902eb77988918401117c70b3cefbc1098c7865 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Sat, 30 Apr 2022 19:25:17 +0800 Subject: [PATCH] fix(typetraits): fix implementation of TIsScopedEnum TIsSwappable and TIsBitwiseConstructible --- .../Source/Private/Testing/ConceptsTesting.cpp | 2 +- .../Source/Private/Testing/TypeTraitsTesting.cpp | 2 +- .../Source/Public/TypeTraits/BitwiseOperations.h | 13 ++++++++----- .../Source/Public/TypeTraits/Swappable.h | 13 +++++++++---- .../Source/Public/TypeTraits/TypeProperties.h | 13 ++----------- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp b/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp index 5d5d25d..0208125 100644 --- a/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp @@ -10,7 +10,7 @@ NAMESPACE_MODULE_BEGIN(Utility) NAMESPACE_BEGIN(Testing) -// Warning: The test here is not a complete test, it is only used to determine whether the environment supports the concepts +// WARNING: The test here is not a complete test, it is only used to determine whether the environment supports the concepts NAMESPACE_UNNAMED_BEGIN diff --git a/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp b/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp index 4e01ba2..26726a1 100644 --- a/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp @@ -10,7 +10,7 @@ NAMESPACE_MODULE_BEGIN(Utility) NAMESPACE_BEGIN(Testing) -// Warning: The test here is not a complete test, it is only used to determine whether the environment supports the traits +// WARNING: The test here is not a complete test, it is only used to determine whether the environment supports the traits NAMESPACE_UNNAMED_BEGIN diff --git a/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h b/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h index 02286ae..a087239 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h @@ -35,11 +35,9 @@ template struct TIsBitwiseConstructible struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible : TIsTriviallyCopyConstructible { }; +template struct TIsBitwiseConstructible : TIsConvertible { }; -template struct TIsBitwiseConstructible : TBoolConstant::Type, typename TRemoveCV::Type>::Value> { }; - -template struct TIsBitwiseConstructible : FFalse { }; +template struct TIsBitwiseConstructible : TBoolConstant::Value ? TIsTriviallyCopyConstructible::Value : false> { }; template <> struct TIsBitwiseConstructible : FTrue { }; template <> struct TIsBitwiseConstructible< int8, uint8> : FTrue { }; @@ -50,6 +48,11 @@ template <> struct TIsBitwiseConstructible< int32, uint32> : FTrue { }; template <> struct TIsBitwiseConstructible : FTrue { }; template <> struct TIsBitwiseConstructible< int64, uint64> : FTrue { }; +template struct TIsBitwiseConstructible : FTrue { }; +template struct TIsBitwiseConstructible : FTrue { }; +template struct TIsBitwiseConstructible< intptr, T*> : FTrue { }; +template struct TIsBitwiseConstructible : FTrue { }; + // It is usually only necessary to specialize TIsBitwiseConstructible and not recommended to specialize TIsBitwiseRelocatable. template struct TIsBitwiseRelocatable; @@ -69,7 +72,7 @@ template struct TIsBitwiseRelocatable struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable : FTrue { }; +template struct TIsBitwiseRelocatable : TBoolConstant::Value> { }; template struct TIsBitwiseRelocatable : TBoolConstant::Value && TIsTriviallyDestructible::Value> { }; diff --git a/Redcraft.Utility/Source/Public/TypeTraits/Swappable.h b/Redcraft.Utility/Source/Public/TypeTraits/Swappable.h index 8ef79e9..2e2817d 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/Swappable.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/Swappable.h @@ -10,18 +10,23 @@ NAMESPACE_MODULE_BEGIN(Utility) NAMESPACE_PRIVATE_BEGIN +template +concept CSwappable = requires(T & A, T & B) { Swap(A, B); }; + template concept CSwappableWith = requires(T&& A, U&& B) { - Swap(A, B); - Swap(B, A); + Swap(Forward(A), Forward(A)); + Swap(Forward(B), Forward(B)); + Swap(Forward(A), Forward(B)); + Swap(Forward(B), Forward(A)); }; NAMESPACE_PRIVATE_END -template struct TIsSwappable : TBoolConstant> { }; -template struct TIsSwappableWith : TBoolConstant> { }; +template struct TIsSwappable : TBoolConstant> { }; +template struct TIsSwappableWith : TBoolConstant> { }; //template struct TIsNothrowSwappable; //template struct TIsNothrowSwappableWith; diff --git a/Redcraft.Utility/Source/Public/TypeTraits/TypeProperties.h b/Redcraft.Utility/Source/Public/TypeTraits/TypeProperties.h index 78493cf..37fe317 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/TypeProperties.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/TypeProperties.h @@ -2,6 +2,7 @@ #include "CoreTypes.h" #include "TypeTraits/HelperClasses.h" +#include "TypeTraits/Miscellaneous.h" #include @@ -25,18 +26,8 @@ template struct TIsUnsigned : TBoolConstant struct TIsBoundedArray : TBoolConstant> { }; template struct TIsUnboundedArray : TBoolConstant> { }; -NAMESPACE_PRIVATE_BEGIN - -uint8(&Resolve(int64))[2]; -uint8 Resolve(...); - template -struct TIsEnumConvertibleToInt : TBoolConstant { }; - -NAMESPACE_PRIVATE_END - -template -struct TIsScopedEnum : TBoolConstant::Value && !NAMESPACE_PRIVATE::TIsEnumConvertibleToInt::Value> { }; +struct TIsScopedEnum : TBoolConstant::Value && !TIsConvertible::Value> { }; NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft)