diff --git a/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp b/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp deleted file mode 100644 index 0583c98..0000000 --- a/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include "Testing/ConceptsTesting.h" - -#include "Miscellaneous/AssertionMacros.h" -#include "Templates/Templates.h" -#include "Concepts/Concepts.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -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 - -NAMESPACE_UNNAMED_BEGIN - -int32 TestObject; -void TestFunction() { } - -struct FTestStructA { }; -struct FTestStructB : FTestStructA { int32 Member; }; -struct FTestStructC { FTestStructC() { } }; -struct FTestStructD { FTestStructD(const FTestStructD&) { } }; -struct FTestStructE { virtual void Member() = 0; }; -struct FTestStructF { int32 MemberA; private: int32 MemberB; }; -struct FTestStructG { char MemberA; float MemberB; short MemberC; int MemberD; }; -struct FTestStructH final : FTestStructE { virtual void Member() override { } }; -struct FTestStructI { int32 MemberA; double MemberB; FTestStructI(int32 A, double B) { } FTestStructI& operator=(int32) { return *this; }; }; -struct FTestStructJ { int32 MemberA; double MemberB; FTestStructJ() { }; }; -struct FTestStructK { int32 MemberA; double MemberB; FTestStructK() = default; }; -struct FTestStructL { int32 MemberA; double MemberB; FTestStructL() = delete; }; -struct FTestStructM { int32 MemberA; double MemberB; FTestStructM(const FTestStructM&) { }; FTestStructM& operator=(const FTestStructM&) { return *this; }; }; -struct FTestStructN { int32 MemberA; double MemberB; FTestStructN(const FTestStructN&) = default; FTestStructN& operator=(const FTestStructN&) = default; }; -struct FTestStructO { int32 MemberA; double MemberB; FTestStructO(const FTestStructO&) = delete; FTestStructO& operator=(const FTestStructO&) = delete; }; -struct FTestStructP { int32 MemberA; double MemberB; FTestStructP(FTestStructP&&) { }; FTestStructP& operator=(FTestStructP&&) { return *this; }; }; -struct FTestStructQ { int32 MemberA; double MemberB; FTestStructQ(FTestStructQ&&) = default; FTestStructQ& operator=(FTestStructQ&&) = default; }; -struct FTestStructR { int32 MemberA; double MemberB; FTestStructR(FTestStructR&&) = delete; FTestStructR& operator=(FTestStructR&&) = delete; }; -struct FTestStructS { int32 MemberA; double MemberB; ~FTestStructS() { } }; -struct FTestStructT { int32 MemberA; double MemberB; ~FTestStructT() = default; }; -struct FTestStructU { int32 MemberA; double MemberB; ~FTestStructU() = delete; }; -struct FTestStructV { int32 MemberA; double MemberB; virtual ~FTestStructV() { }; }; -struct FTestStructW { int32 MemberA; double MemberB; operator FTestStructV() { return FTestStructV(); } }; - -enum ETestEnum { }; -enum class ETestEnumClass { }; -enum class ETestEnumClass8 : uint8 { }; -enum class ETestEnumClass32 : uint32 { }; -enum class ETestEnumClass64 : uint64 { }; - -union FTestUnion { }; - -NAMESPACE_UNNAMED_END - -void TestConcepts() -{ - // Derived.h - - always_check(!(CDerivedFrom)); - always_check((CDerivedFrom)); - always_check(!(CDerivedFrom)); - - // Common.h - - always_check((CCommonWith)); - always_check((CCommonWith)); - always_check((CCommonWith)); - always_check(!(CCommonWith)); - - always_check((CCommonReferenceWith)); - always_check((CCommonReferenceWith)); - always_check((CCommonReferenceWith)); - always_check(!(CCommonReferenceWith)); - - // Comparable.h - - always_check((CEqualityComparable)); - always_check(!(CEqualityComparable)); - - always_check((CEqualityComparableWith)); - always_check((CEqualityComparableWith)); - always_check(!(CEqualityComparableWith)); - - always_check((CTotallyOrdered)); - always_check(!(CTotallyOrdered)); - - always_check((CTotallyOrderedWith)); - always_check((CTotallyOrderedWith)); - always_check(!(CTotallyOrderedWith)); - - // Objects.h - - always_check(CMovable); - always_check(CCopyable); - always_check(CSemiregular); - always_check(CRegular); - - always_check(CMovable); - always_check(!CCopyable); - always_check(!CSemiregular); - always_check(!CRegular); - - always_check(CMovable); - always_check(CCopyable); - always_check(!CSemiregular); - always_check(!CRegular); - - // Swappable.h - - always_check(CSwappable); - always_check(CSwappable); - always_check(CSwappable); - always_check(!CSwappable); - - always_check((CSwappableWith)); - -} - -NAMESPACE_END(Testing) - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp b/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp index 5b52360..91461d2 100644 --- a/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp @@ -746,8 +746,8 @@ void TestTuple() always_check(CDefaultConstructible); always_check(CTriviallyDefaultConstructible); - always_check(CConstructible); - always_check(CTriviallyConstructible); + always_check(CConstructibleFrom); + always_check(CTriviallyConstructibleFrom); always_check(CCopyConstructible); always_check(CTriviallyCopyConstructible); always_check(CMoveConstructible); diff --git a/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp b/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp index ff3f8a4..47bcead 100644 --- a/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/TypeTraitsTesting.cpp @@ -240,13 +240,13 @@ void TestTypeTraits() always_check(CTriviallyDefaultConstructible); always_check(!CTriviallyDefaultConstructible); - always_check(!(CConstructible)); - always_check((CConstructible)); - always_check((CConstructible)); + always_check(!(CConstructibleFrom)); + always_check((CConstructibleFrom)); + always_check((CConstructibleFrom)); - always_check(!(CTriviallyConstructible)); - always_check((CTriviallyConstructible)); - always_check(!(CTriviallyConstructible)); + always_check(!(CTriviallyConstructibleFrom)); + always_check((CTriviallyConstructibleFrom)); + always_check(!(CTriviallyConstructibleFrom)); always_check(CCopyConstructible); always_check(CCopyConstructible); @@ -264,13 +264,13 @@ void TestTypeTraits() always_check(CTriviallyMoveConstructible); always_check(!CTriviallyMoveConstructible); - always_check(!(CAssignable)); - always_check((CAssignable)); - always_check((CAssignable)); + always_check(!(CAssignableFrom)); + always_check((CAssignableFrom)); + always_check((CAssignableFrom)); - always_check(!(CTriviallyAssignable)); - always_check((CTriviallyAssignable)); - always_check(!(CTriviallyAssignable)); + always_check(!(CTriviallyAssignableFrom)); + always_check((CTriviallyAssignableFrom)); + always_check(!(CTriviallyAssignableFrom)); always_check(CCopyAssignable); always_check(CCopyAssignable); @@ -458,15 +458,25 @@ void TestTypeTraits() always_check((CSameAs::Type>)); always_check((CSameAs::Type>)); always_check((CSameAs::Type>)); + + always_check((CCommonWith)); + always_check((CCommonWith)); + always_check((CCommonWith)); + always_check(!(CCommonWith)); + + always_check((CCommonReferenceWith)); + always_check((CCommonReferenceWith)); + always_check((CCommonReferenceWith)); + always_check(!(CCommonReferenceWith)); // Swappable.h - always_check(TIsSwappable::Value); - always_check(TIsSwappable::Value); - always_check(TIsSwappable::Value); - always_check(!TIsSwappable::Value); + always_check(CSwappable); + always_check(CSwappable); + always_check(CSwappable); + always_check(!CSwappable); - always_check((TIsSwappableWith::Value)); + always_check((CSwappableWith)); // CopyQualifiers.h @@ -553,6 +563,39 @@ void TestTypeTraits() always_check(CBooleanTestable); always_check(!CBooleanTestable); + // Objects.h + + always_check(CMovable); + always_check(CCopyable); + always_check(CSemiregular); + always_check(CRegular); + + always_check(CMovable); + always_check(!CCopyable); + always_check(!CSemiregular); + always_check(!CRegular); + + always_check(CMovable); + always_check(CCopyable); + always_check(!CSemiregular); + always_check(!CRegular); + + // Comparable.h + + always_check((CEqualityComparable)); + always_check(!(CEqualityComparable)); + + always_check((CEqualityComparableWith)); + always_check((CEqualityComparableWith)); + always_check(!(CEqualityComparableWith)); + + always_check((CTotallyOrdered)); + always_check(!(CTotallyOrdered)); + + always_check((CTotallyOrderedWith)); + always_check((CTotallyOrderedWith)); + always_check(!(CTotallyOrderedWith)); + } NAMESPACE_END(Testing) diff --git a/Redcraft.Utility/Source/Public/Concepts/Assignable.h b/Redcraft.Utility/Source/Public/Concepts/Assignable.h deleted file mode 100644 index 82baf2d..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/Assignable.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "Concepts/Common.h" -#include "Templates/Utility.h" -#include "TypeTraits/TypeTraits.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -template -concept CAssignableFrom = - CLValueReference && - CCommonReferenceWith::Type&, const typename TRemoveReference::Type&> && - requires(T A, U&& B) - { - { A = Forward(B) } -> CSameAs; - }; - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/BooleanTestable.h b/Redcraft.Utility/Source/Public/Concepts/BooleanTestable.h deleted file mode 100644 index dbc924c..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/BooleanTestable.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "TypeTraits/TypeTraits.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/BuiltinType.h b/Redcraft.Utility/Source/Public/Concepts/BuiltinType.h deleted file mode 100644 index dbc924c..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/BuiltinType.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "TypeTraits/TypeTraits.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/Common.h b/Redcraft.Utility/Source/Public/Concepts/Common.h deleted file mode 100644 index 0c39350..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/Common.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "Concepts/Same.h" -#include "Templates/Utility.h" -#include "Concepts/Convertible.h" -#include "TypeTraits/TypeTraits.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -template -concept CCommonReferenceWith = - requires - { - typename TCommonReference::Type; - typename TCommonReference::Type; - } && - CSameAs::Type, typename TCommonReference::Type> && - CConvertibleTo::Type>&& - CConvertibleTo::Type>; - -template -concept CCommonWith = - requires - { - typename TCommonType::Type; - typename TCommonType::Type; - requires CSameAs::Type, typename TCommonType::Type>; - static_cast::Type>(DeclVal()); - static_cast::Type>(DeclVal()); - } && - CCommonReferenceWith && - CCommonReferenceWith::Type&, typename TCommonReference::Type> && - CSameAs::Type, typename TCommonReference::Type>; - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/Concepts.h b/Redcraft.Utility/Source/Public/Concepts/Concepts.h deleted file mode 100644 index 2a28385..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/Concepts.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "Concepts/Same.h" -#include "Concepts/Derived.h" -#include "Concepts/Objects.h" -#include "Concepts/Invocable.h" -#include "Concepts/Swappable.h" -#include "Concepts/Assignable.h" -#include "Concepts/Comparable.h" -#include "Concepts/BuiltinType.h" -#include "Concepts/Convertible.h" -#include "Concepts/Destructible.h" -#include "Concepts/Constructible.h" -#include "Concepts/BooleanTestable.h" diff --git a/Redcraft.Utility/Source/Public/Concepts/Constructible.h b/Redcraft.Utility/Source/Public/Concepts/Constructible.h deleted file mode 100644 index 76b71b8..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/Constructible.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "Concepts/Convertible.h" -#include "TypeTraits/TypeTraits.h" -#include "Concepts/Destructible.h" - -#include - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -template -concept CConstructibleFrom = CDestructible && CConstructible; - -template -concept CDefaultInitializable = CConstructibleFrom && requires { T{}; ::new(static_cast(nullptr)) T; }; - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/Convertible.h b/Redcraft.Utility/Source/Public/Concepts/Convertible.h deleted file mode 100644 index dbc924c..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/Convertible.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "TypeTraits/TypeTraits.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/Derived.h b/Redcraft.Utility/Source/Public/Concepts/Derived.h deleted file mode 100644 index 7d81d02..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/Derived.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "TypeTraits/TypeTraits.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -template -concept CDerivedFrom = CBaseOf && CConvertibleTo; - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/Destructible.h b/Redcraft.Utility/Source/Public/Concepts/Destructible.h deleted file mode 100644 index dbc924c..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/Destructible.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "TypeTraits/TypeTraits.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/Invocable.h b/Redcraft.Utility/Source/Public/Concepts/Invocable.h deleted file mode 100644 index dbc924c..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/Invocable.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "TypeTraits/TypeTraits.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/Same.h b/Redcraft.Utility/Source/Public/Concepts/Same.h deleted file mode 100644 index dbc924c..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/Same.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "TypeTraits/TypeTraits.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/Swappable.h b/Redcraft.Utility/Source/Public/Concepts/Swappable.h deleted file mode 100644 index 87d72e8..0000000 --- a/Redcraft.Utility/Source/Public/Concepts/Swappable.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "Concepts/Common.h" -#include "Templates/Utility.h" -#include "TypeTraits/TypeTraits.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -template -concept CSwappable = requires(T& A, T& B) { Swap(A, B); }; - -template -concept CSwappableWith = CCommonReferenceWith && - requires(T&& A, U&& B) - { - Swap(Forward(A), Forward(A)); - Swap(Forward(B), Forward(B)); - Swap(Forward(A), Forward(B)); - Swap(Forward(B), Forward(A)); - }; - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Memory/Alignment.h b/Redcraft.Utility/Source/Public/Memory/Alignment.h index 455996f..4c1577d 100644 --- a/Redcraft.Utility/Source/Public/Memory/Alignment.h +++ b/Redcraft.Utility/Source/Public/Memory/Alignment.h @@ -10,7 +10,7 @@ NAMESPACE_MODULE_BEGIN(Utility) NAMESPACE_BEGIN(Memory) -FORCEINLINE constexpr bool IsValidAlignment(size_t Alignment) { return !(Alignment & (Alignment - 1)); } +constexpr bool IsValidAlignment(size_t Alignment) { return !(Alignment & (Alignment - 1)); } template requires CIntegral || CPointer FORCEINLINE constexpr T Align(T InValue, size_t Alignment) diff --git a/Redcraft.Utility/Source/Public/Memory/MemoryOperator.h b/Redcraft.Utility/Source/Public/Memory/MemoryOperator.h index 7ef0fd8..5dd5282 100644 --- a/Redcraft.Utility/Source/Public/Memory/MemoryOperator.h +++ b/Redcraft.Utility/Source/Public/Memory/MemoryOperator.h @@ -3,7 +3,6 @@ #include "CoreTypes.h" #include "Memory/Memory.h" #include "Templates/Utility.h" -#include "Concepts/Comparable.h" #include "TypeTraits/TypeTraits.h" NAMESPACE_REDCRAFT_BEGIN @@ -16,7 +15,7 @@ template requires CDefaultConstructible FORCEINLINE void DefaultConstruct(ElementType* Address, size_t Count = 1) { - if constexpr (TIsZeroConstructible::Value) + if constexpr (CZeroConstructible) { Memory::Memset(Address, 0, sizeof(ElementType) * Count); } @@ -32,11 +31,11 @@ FORCEINLINE void DefaultConstruct(ElementType* Address, size_t Count = 1) } } -template - requires CConstructible +template + requires CConstructibleFrom FORCEINLINE void Construct(DestinationElementType* Destination, const SourceElementType* Source, size_t Count = 1) { - if constexpr (TIsBitwiseConstructible::Value) + if constexpr (CBitwiseConstructible) { Memory::Memcpy(Destination, Source, sizeof(SourceElementType) * Count); } @@ -92,11 +91,11 @@ FORCEINLINE void MoveConstruct(ElementType* Destination, ElementType* Source, si } } -template - requires CConstructible && CDestructible +template + requires CConstructibleFrom && CDestructible FORCEINLINE void RelocateConstruct(DestinationElementType* Destination, SourceElementType* Source, size_t Count = 1) { - if constexpr (TIsBitwiseRelocatable::Value) + if constexpr (CBitwiseRelocatable) { Memory::Memmove(Destination, Source, sizeof(SourceElementType) * Count); } @@ -173,7 +172,7 @@ template requires CEqualityComparable FORCEINLINE bool Compare(const ElementType* LHS, const ElementType* RHS, size_t Count = 1) { - if constexpr (TIsBitwiseComparable::Value) + if constexpr (CBitwiseComparable) { return !Memory::Memcmp(LHS, RHS, sizeof(ElementType) * Count); } diff --git a/Redcraft.Utility/Source/Public/Miscellaneous/Compare.h b/Redcraft.Utility/Source/Public/Miscellaneous/Compare.h index 98c0699..59948af 100644 --- a/Redcraft.Utility/Source/Public/Miscellaneous/Compare.h +++ b/Redcraft.Utility/Source/Public/Miscellaneous/Compare.h @@ -2,7 +2,6 @@ #include "CoreTypes.h" #include "Templates/Utility.h" -#include "Concepts/Concepts.h" #include "TypeTraits/TypeTraits.h" #include diff --git a/Redcraft.Utility/Source/Public/Templates/Any.h b/Redcraft.Utility/Source/Public/Templates/Any.h index 175c018..6fe1989 100644 --- a/Redcraft.Utility/Source/Public/Templates/Any.h +++ b/Redcraft.Utility/Source/Public/Templates/Any.h @@ -69,15 +69,15 @@ struct alignas(InlineAlignment) TAny } template requires CDestructible::Type> - && CConstructible::Type, Types...> + && CConstructibleFrom::Type, Types...> FORCEINLINE explicit TAny(TInPlaceType, Types&&... Args) { using SelectedType = typename TDecay::Type; EmplaceImpl(Forward(Args)...); } - template requires (!CSameAs::Type, TAny>) && (!TIsTInPlaceType::Type>::Value) - && CDestructible::Type> && CConstructible::Type, T&&> + template requires (!CSameAs::Type, TAny>) && (!CTInPlaceType::Type>) + && CDestructible::Type> && CConstructibleFrom::Type, T&&> FORCEINLINE TAny(T&& InValue) : TAny(InPlaceType::Type>, Forward(InValue)) { } @@ -184,8 +184,8 @@ struct alignas(InlineAlignment) TAny return *this; } - template requires (!CSameAs::Type, TAny>) && (!TIsTInPlaceType::Type>::Value) - && CDestructible::Type> && CConstructible::Type, T&&> + template requires (!CSameAs::Type, TAny>) && (!CTInPlaceType::Type>) + && CDestructible::Type> && CConstructibleFrom::Type, T&&> FORCEINLINE TAny& operator=(T&& InValue) { using SelectedType = typename TDecay::Type; @@ -204,7 +204,7 @@ struct alignas(InlineAlignment) TAny } template requires CDestructible::Type> - && CConstructible::Type, T&&> + && CConstructibleFrom::Type, T&&> FORCEINLINE typename TDecay::Type& Emplace(Types&&... Args) { ResetImpl(); @@ -430,9 +430,15 @@ constexpr bool operator==(const TAny& LHS, FInvalid return !LHS.IsValid(); } +NAMESPACE_PRIVATE_BEGIN + template struct TIsTAny : FFalse { }; template struct TIsTAny> : FTrue { }; +NAMESPACE_PRIVATE_END + +template concept CTAny = NAMESPACE_PRIVATE::TIsTAny::Value; + using FAny = TAny; static_assert(sizeof(FAny) == 64, "The byte size of FAny is unexpected"); diff --git a/Redcraft.Utility/Source/Public/Templates/Function.h b/Redcraft.Utility/Source/Public/Templates/Function.h index 012c46d..94c712d 100644 --- a/Redcraft.Utility/Source/Public/Templates/Function.h +++ b/Redcraft.Utility/Source/Public/Templates/Function.h @@ -28,6 +28,8 @@ struct TFunction; template requires CFunction && (Memory::IsValidAlignment(InlineAlignment)) struct TUniqueFunction; +NAMESPACE_PRIVATE_BEGIN + template struct TIsTFunctionRef : FFalse { }; template struct TIsTFunctionRef> : FTrue { }; @@ -37,12 +39,18 @@ template struct TIsTFunction template struct TIsTUniqueFunction : FFalse { }; template struct TIsTUniqueFunction> : FTrue { }; +NAMESPACE_PRIVATE_END + +template concept CTFunctionRef = NAMESPACE_PRIVATE::TIsTFunctionRef::Value; +template concept CTFunction = NAMESPACE_PRIVATE::TIsTFunction::Value; +template concept CTUniqueFunction = NAMESPACE_PRIVATE::TIsTUniqueFunction::Value; + NAMESPACE_PRIVATE_BEGIN template constexpr bool FunctionIsBound(const T& Func) { - if constexpr (CPointer || CMemberPointer || TIsTFunctionRef::Value || TIsTFunction::Value || TIsTUniqueFunction::Value) + if constexpr (CPointer || CMemberPointer || CTFunctionRef || CTFunction || CTUniqueFunction) { return !!Func; } @@ -241,7 +249,7 @@ public: TFunctionRef& operator=(const TFunctionRef& InValue) = delete; TFunctionRef& operator=(TFunctionRef&& InValue) = delete; - template requires (!TIsTFunctionRef::Type>::Value) && (!TIsTInPlaceType::Type>::Value) + template requires (!CTFunctionRef::Type>) && (!CTInPlaceType::Type>) && NAMESPACE_PRIVATE::TIsInvocableSignature::Type>::Value FORCEINLINE TFunctionRef(T&& InValue) { @@ -294,9 +302,9 @@ public: return *this; } - template requires (!TIsTInPlaceType::Type>::Value) - && (!TIsTFunctionRef::Type>::Value) && (!TIsTFunction::Type>::Value) && (!TIsTUniqueFunction::Type>::Value) - && CConstructible::Type, T&&> && CCopyConstructible::Type> + template requires (!CTInPlaceType::Type>) + && (!CTFunctionRef::Type>) && (!CTFunction::Type>) && (!CTUniqueFunction::Type>) + && CConstructibleFrom::Type, T&&> && CCopyConstructible::Type> && NAMESPACE_PRIVATE::TIsInvocableSignature::Type>::Value FORCEINLINE TFunction(T&& InValue) { @@ -306,7 +314,7 @@ public: } template requires NAMESPACE_PRIVATE::TIsInvocableSignature::Type>::Value - && CConstructible::Type, ArgTypes...> && CCopyConstructible::Type> + && CConstructibleFrom::Type, ArgTypes...> && CCopyConstructible::Type> FORCEINLINE TFunction(TInPlaceType, ArgTypes&&... Args) { using DecayedType = typename TDecay::Type; @@ -316,8 +324,8 @@ public: constexpr TFunction& operator=(nullptr_t) { Super::ResetImpl(); return *this; } template requires NAMESPACE_PRIVATE::TIsInvocableSignature::Type>::Value - && (!TIsTFunctionRef::Type>::Value) && (!TIsTFunction::Type>::Value) && (!TIsTUniqueFunction::Type>::Value) - && CConstructible::Type, T&&> && CCopyConstructible::Type> + && (!CTFunctionRef::Type>) && (!CTFunction::Type>) && (!CTUniqueFunction::Type>) + && CConstructibleFrom::Type, T&&> && CCopyConstructible::Type> FORCEINLINE TFunction& operator=(T&& InValue) { using DecayedType = typename TDecay::Type; @@ -329,7 +337,7 @@ public: } template requires NAMESPACE_PRIVATE::TIsInvocableSignature::Type>::Value - && CConstructible::Type, ArgTypes...>&& CCopyConstructible::Type> + && CConstructibleFrom::Type, ArgTypes...>&& CCopyConstructible::Type> FORCEINLINE typename TDecay::Type& Emplace(ArgTypes&&... Args) { using DecayedType = typename TDecay::Type; @@ -397,9 +405,9 @@ public: return *this; } - template requires (!TIsTInPlaceType::Type>::Value) - && (!TIsTFunctionRef::Type>::Value) && (!TIsTFunction::Type>::Value) && (!TIsTUniqueFunction::Type>::Value) - && CConstructible::Type, T&&> && CMoveConstructible::Type> + template requires (!CTInPlaceType::Type>) + && (!CTFunctionRef::Type>) && (!CTFunction::Type>) && (!CTUniqueFunction::Type>) + && CConstructibleFrom::Type, T&&> && CMoveConstructible::Type> && NAMESPACE_PRIVATE::TIsInvocableSignature::Type>::Value FORCEINLINE TUniqueFunction(T&& InValue) { @@ -409,7 +417,7 @@ public: } template requires NAMESPACE_PRIVATE::TIsInvocableSignature::Type>::Value - && CConstructible::Type, ArgTypes...> && CMoveConstructible::Type> + && CConstructibleFrom::Type, ArgTypes...> && CMoveConstructible::Type> FORCEINLINE TUniqueFunction(TInPlaceType, ArgTypes&&... Args) { using DecayedType = typename TDecay::Type; @@ -419,8 +427,8 @@ public: constexpr TUniqueFunction& operator=(nullptr_t) { Super::ResetImpl(); return *this; } template requires NAMESPACE_PRIVATE::TIsInvocableSignature::Type>::Value - && (!TIsTFunctionRef::Type>::Value) && (!TIsTFunction::Type>::Value) && (!TIsTUniqueFunction::Type>::Value) - && CConstructible::Type, T&&>&& CMoveConstructible::Type> + && (!CTFunctionRef::Type>) && (!CTFunction::Type>) && (!CTUniqueFunction::Type>) + && CConstructibleFrom::Type, T&&>&& CMoveConstructible::Type> FORCEINLINE TUniqueFunction& operator=(T&& InValue) { using DecayedType = typename TDecay::Type; @@ -432,7 +440,7 @@ public: } template requires NAMESPACE_PRIVATE::TIsInvocableSignature::Type>::Value - && CConstructible::Type, ArgTypes...>&& CMoveConstructible::Type> + && CConstructibleFrom::Type, ArgTypes...>&& CMoveConstructible::Type> FORCEINLINE typename TDecay::Type& Emplace(ArgTypes&&... Args) { using DecayedType = typename TDecay::Type; diff --git a/Redcraft.Utility/Source/Public/Templates/Optional.h b/Redcraft.Utility/Source/Public/Templates/Optional.h index 05105cb..d1cf029 100644 --- a/Redcraft.Utility/Source/Public/Templates/Optional.h +++ b/Redcraft.Utility/Source/Public/Templates/Optional.h @@ -3,7 +3,6 @@ #include "CoreTypes.h" #include "Templates/Utility.h" #include "Templates/TypeHash.h" -#include "Concepts/Comparable.h" #include "TypeTraits/TypeTraits.h" #include "Miscellaneous/Compare.h" #include "Miscellaneous/AssertionMacros.h" @@ -19,18 +18,18 @@ private: template struct TAllowUnwrapping : TBoolConstant& > - || CConstructible& > - || CConstructible&&> - || CConstructible&&> + CConstructibleFrom& > + || CConstructibleFrom& > + || CConstructibleFrom&&> + || CConstructibleFrom&&> || CConvertibleTo< TOptional&, OptionalType> || CConvertibleTo&, OptionalType> || CConvertibleTo< TOptional&&, OptionalType> || CConvertibleTo&&, OptionalType> - || CAssignable& > - || CAssignable& > - || CAssignable&&> - || CAssignable&&> + || CAssignableFrom& > + || CAssignableFrom& > + || CAssignableFrom&&> + || CAssignableFrom&&> )> { }; public: @@ -41,14 +40,14 @@ public: constexpr TOptional(FInvalid) : TOptional() { } - template requires CConstructible + template requires CConstructibleFrom constexpr explicit TOptional(FInPlace, Types&&... Args) : bIsValid(true) { new(&Value) OptionalType(Forward(Args)...); } - template requires CConstructible + template requires CConstructibleFrom && (!CSameAs::Type, FInPlace>) && (!CSameAs::Type, TOptional>) constexpr explicit (!CConvertibleTo) TOptional(T&& InValue) : TOptional(InPlace, Forward(InValue)) @@ -66,14 +65,14 @@ public: if (InValue.IsValid()) new(&Value) OptionalType(MoveTemp(InValue.GetValue())); } - template requires CConstructible && TAllowUnwrapping::Value + template requires CConstructibleFrom && TAllowUnwrapping::Value constexpr explicit (!CConvertibleTo) TOptional(const TOptional& InValue) : bIsValid(InValue.IsValid()) { if (InValue.IsValid()) new(&Value) OptionalType(InValue.GetValue()); } - template requires CConstructible && TAllowUnwrapping::Value + template requires CConstructibleFrom && TAllowUnwrapping::Value constexpr explicit (!CConvertibleTo) TOptional(TOptional&& InValue) : bIsValid(InValue.IsValid()) { @@ -125,7 +124,7 @@ public: return *this; } - template requires CConstructible && CAssignable && TAllowUnwrapping::Value + template requires CConstructibleFrom && CAssignableFrom && TAllowUnwrapping::Value constexpr TOptional& operator=(const TOptional& InValue) { if (!InValue.IsValid()) @@ -144,7 +143,7 @@ public: return *this; } - template requires CConstructible && CAssignable && TAllowUnwrapping::Value + template requires CConstructibleFrom && CAssignableFrom && TAllowUnwrapping::Value constexpr TOptional& operator=(TOptional&& InValue) { if (!InValue.IsValid()) @@ -163,7 +162,7 @@ public: return *this; } - template requires CConstructible && CAssignable + template requires CConstructibleFrom && CAssignableFrom constexpr TOptional& operator=(T&& InValue) { if (IsValid()) GetValue() = Forward(InValue); @@ -176,7 +175,7 @@ public: return *this; } - template requires CConstructible + template requires CConstructibleFrom constexpr OptionalType& Emplace(ArgTypes&&... Args) { Reset(); @@ -223,7 +222,7 @@ public: return NAMESPACE_REDCRAFT::GetTypeHash(GetValue()); } - template requires CMoveConstructible && TIsSwappable::Value + template requires CMoveConstructible && CSwappable constexpr void Swap(TOptional& InValue) { if (!IsValid() && !InValue.IsValid()) return; @@ -289,21 +288,27 @@ constexpr TOptional::Type> MakeOptional(FInvalid) return TOptional::Type>(Invalid); } -template requires CDestructible && CConstructible +template requires CDestructible && CConstructibleFrom constexpr TOptional MakeOptional(T&& InValue) { return TOptional(Forward(InValue)); } -template requires CDestructible && CConstructible +template requires CDestructible && CConstructibleFrom constexpr TOptional MakeOptional(Types&&... Args) { return TOptional(InPlace, Forward(Args)...); } +NAMESPACE_PRIVATE_BEGIN + template struct TIsTOptional : FFalse { }; template struct TIsTOptional> : FTrue { }; +NAMESPACE_PRIVATE_END + +template concept CTOptional = NAMESPACE_PRIVATE::TIsTOptional::Value; + NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h b/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h index 3f415f6..9045462 100644 --- a/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h +++ b/Redcraft.Utility/Source/Public/Templates/ReferenceWrapper.h @@ -99,9 +99,15 @@ constexpr TReferenceWrapper Ref(TReferenceWrapper InValue) return Ref(InValue.Get()); } +NAMESPACE_PRIVATE_BEGIN + template struct TIsTReferenceWrapper : FFalse { }; template struct TIsTReferenceWrapper> : FTrue { }; +NAMESPACE_PRIVATE_END + +template concept CTReferenceWrapper = NAMESPACE_PRIVATE::TIsTReferenceWrapper::Value; + template struct TUnwrapReference { using Type = T; }; template struct TUnwrapReference> { using Type = T&; }; @@ -115,19 +121,19 @@ private: using OptionalType = TReferenceWrapper; template - struct TAllowUnwrapping : TBoolConstant& > - || CConstructible& > - || CConstructible&&> - || CConstructible&&> + struct TAllowUnwrapping : TBoolConstant < !( + CConstructibleFrom& > + || CConstructibleFrom& > + || CConstructibleFrom&&> + || CConstructibleFrom&&> || CConvertibleTo< TOptional&, OptionalType> || CConvertibleTo&, OptionalType> || CConvertibleTo< TOptional&&, OptionalType> || CConvertibleTo&&, OptionalType> - || CAssignable& > - || CAssignable& > - || CAssignable&&> - || CAssignable&&> + || CAssignableFrom& > + || CAssignableFrom& > + || CAssignableFrom&&> + || CAssignableFrom&&> )> { }; public: @@ -138,12 +144,12 @@ public: constexpr TOptional(FInvalid) : TOptional() { } - template requires CConstructible + template requires CConstructibleFrom constexpr explicit TOptional(FInPlace, Types&&... Args) : Reference(Forward(Args)...) { } - template requires CConstructible + template requires CConstructibleFrom && (!CSameAs::Type, FInPlace>) && (!CSameAs::Type, TOptional>) constexpr explicit (!CConvertibleTo) TOptional(T&& InValue) : TOptional(InPlace, Forward(InValue)) @@ -152,7 +158,7 @@ public: TOptional(const TOptional& InValue) = default; TOptional(TOptional&& InValue) = default; - template requires CConstructible && TAllowUnwrapping::Value + template requires CConstructibleFrom && TAllowUnwrapping::Value constexpr explicit (!CConvertibleTo) TOptional(const TOptional& InValue) : Reference(InValue.Reference) { } @@ -162,21 +168,21 @@ public: TOptional& operator=(const TOptional& InValue) = default; TOptional& operator=(TOptional&& InValue) = default; - template requires CConstructible && CAssignable && TAllowUnwrapping::Value + template requires CConstructibleFrom && CAssignableFrom && TAllowUnwrapping::Value constexpr TOptional& operator=(const TOptional& InValue) { Reference = InValue.Reference; return *this; } - template requires CConstructible && CAssignable + template requires CConstructibleFrom && CAssignableFrom constexpr TOptional& operator=(T&& InValue) { Reference = InValue; return *this; } - template requires CConstructible + template requires CConstructibleFrom constexpr OptionalType& Emplace(ArgTypes&&... Args) { Reference = TReferenceWrapper(Forward(Args)...); diff --git a/Redcraft.Utility/Source/Public/Templates/Tuple.h b/Redcraft.Utility/Source/Public/Templates/Tuple.h index e4b9455..9b1b069 100644 --- a/Redcraft.Utility/Source/Public/Templates/Tuple.h +++ b/Redcraft.Utility/Source/Public/Templates/Tuple.h @@ -236,23 +236,23 @@ public: TTuple() = default; template requires (ElementSize > 0) && (sizeof...(ArgTypes) == ElementSize) - && (true && ... && CConstructible) + && (true && ... && CConstructibleFrom) && (true && ... && CConvertibleTo) constexpr TTuple(ArgTypes&&... Args) : Super(NAMESPACE_PRIVATE::ForwardingConstructor, Forward(Args)...) { } template requires (ElementSize > 0) && (sizeof...(ArgTypes) == ElementSize) - && (true && ... && CConstructible) + && (true && ... && CConstructibleFrom) && (!(true && ... && CConvertibleTo)) constexpr explicit TTuple(ArgTypes&&... Args) : Super(NAMESPACE_PRIVATE::ForwardingConstructor, Forward(Args)...) { } template requires (sizeof...(OtherTypes) == ElementSize) - && (true && ... && CConstructible) + && (true && ... && CConstructibleFrom) && ((ElementSize != 1) || !(CConvertibleTo&, typename TElementType<0>::Type> - || CConstructible::Type, const TTuple&> + || CConstructibleFrom::Type, const TTuple&> || CSameAs::Type, typename TTuple::template TElementType<0>::Type>)) && (true && ... && CConvertibleTo) constexpr TTuple(const TTuple& InValue) @@ -260,9 +260,9 @@ public: { } template requires (sizeof...(OtherTypes) == ElementSize) - && (true && ... && CConstructible) + && (true && ... && CConstructibleFrom) && ((ElementSize != 1) || !(CConvertibleTo&, typename TElementType<0>::Type> - || CConstructible::Type, const TTuple&> + || CConstructibleFrom::Type, const TTuple&> || CSameAs::Type, typename TTuple::template TElementType<0>::Type>)) && (!(true && ... && CConvertibleTo)) constexpr explicit TTuple(const TTuple& InValue) @@ -270,9 +270,9 @@ public: { } template requires (sizeof...(OtherTypes) == ElementSize) - && (true && ... && CConstructible) + && (true && ... && CConstructibleFrom) && ((ElementSize != 1) || !(CConvertibleTo&&, typename TElementType<0>::Type> - || CConstructible::Type, TTuple&&> + || CConstructibleFrom::Type, TTuple&&> || CSameAs::Type, typename TTuple::template TElementType<0>::Type>)) && (true && ... && CConvertibleTo) constexpr TTuple(TTuple&& InValue) @@ -280,9 +280,9 @@ public: { } template requires (sizeof...(OtherTypes) == ElementSize) - && (true && ... && CConstructible) + && (true && ... && CConstructibleFrom) && ((ElementSize != 1) || !(CConvertibleTo&&, typename TElementType<0>::Type> - || CConstructible::Type, TTuple&&> + || CConstructibleFrom::Type, TTuple&&> || CSameAs::Type, typename TTuple::template TElementType<0>::Type>)) && (!(true && ... && CConvertibleTo)) constexpr explicit TTuple(TTuple&& InValue) @@ -293,7 +293,7 @@ public: TTuple(TTuple&&) = default; template requires (sizeof...(OtherTypes) == ElementSize) - && (true && ... && CAssignable) + && (true && ... && CAssignableFrom) constexpr TTuple& operator=(const TTuple& InValue) { Helper::Assign(*this, InValue); @@ -301,7 +301,7 @@ public: } template requires (sizeof...(OtherTypes) == ElementSize) - && (true && ... && CAssignable) + && (true && ... && CAssignableFrom) constexpr TTuple& operator=(TTuple&& InValue) { Helper::Assign(*this, MoveTemp(InValue)); @@ -365,21 +365,21 @@ public: template requires (true && ... && (CInvocable && !CSameAs::Type>)) constexpr auto Transform(F&& Func) volatile&& { return Helper::Transform(Forward(Func), static_cast< volatile TTuple&&>(*this)); } template requires (true && ... && (CInvocable && !CSameAs::Type>)) constexpr auto Transform(F&& Func) const volatile&& { return Helper::Transform(Forward(Func), static_cast(*this)); } - template requires CConstructible constexpr T Construct() & { return Helper::template Construct(static_cast< TTuple& >(*this)); } - template requires CConstructible constexpr T Construct() const & { return Helper::template Construct(static_cast(*this)); } - template requires CConstructible constexpr T Construct() volatile& { return Helper::template Construct(static_cast< volatile TTuple& >(*this)); } - template requires CConstructible constexpr T Construct() const volatile& { return Helper::template Construct(static_cast(*this)); } - template requires CConstructible constexpr T Construct() && { return Helper::template Construct(static_cast< TTuple&&>(*this)); } - template requires CConstructible constexpr T Construct() const && { return Helper::template Construct(static_cast(*this)); } - template requires CConstructible constexpr T Construct() volatile&& { return Helper::template Construct(static_cast< volatile TTuple&&>(*this)); } - template requires CConstructible constexpr T Construct() const volatile&& { return Helper::template Construct(static_cast(*this)); } + template requires CConstructibleFrom constexpr T Construct() & { return Helper::template Construct(static_cast< TTuple& >(*this)); } + template requires CConstructibleFrom constexpr T Construct() const & { return Helper::template Construct(static_cast(*this)); } + template requires CConstructibleFrom constexpr T Construct() volatile& { return Helper::template Construct(static_cast< volatile TTuple& >(*this)); } + template requires CConstructibleFrom constexpr T Construct() const volatile& { return Helper::template Construct(static_cast(*this)); } + template requires CConstructibleFrom constexpr T Construct() && { return Helper::template Construct(static_cast< TTuple&&>(*this)); } + template requires CConstructibleFrom constexpr T Construct() const && { return Helper::template Construct(static_cast(*this)); } + template requires CConstructibleFrom constexpr T Construct() volatile&& { return Helper::template Construct(static_cast< volatile TTuple&&>(*this)); } + template requires CConstructibleFrom constexpr T Construct() const volatile&& { return Helper::template Construct(static_cast(*this)); } constexpr size_t GetTypeHash() const requires (true && ... && CHashable) { return [this](TIndexSequence) -> size_t { return HashCombine(NAMESPACE_REDCRAFT::GetTypeHash(GetValue())...); } (TMakeIndexSequence()); } - constexpr void Swap(TTuple& InValue) requires (true && ... && (CMoveConstructible&& TIsSwappable::Value)) + constexpr void Swap(TTuple& InValue) requires (true && ... && (CMoveConstructible&& CSwappable)) { [&A = *this, &B = InValue](TIndexSequence) { ((NAMESPACE_REDCRAFT::Swap(A.template GetValue(), B.template GetValue())), ...); } (TMakeIndexSequence()); } @@ -392,16 +392,22 @@ TTuple(Types...) -> TTuple; template using TPair = TTuple; +NAMESPACE_PRIVATE_BEGIN + template struct TIsTTuple : FFalse { }; template struct TIsTTuple> : FTrue { }; -template requires TIsTTuple::Type>::Value +NAMESPACE_PRIVATE_END + +template concept CTTuple = NAMESPACE_PRIVATE::TIsTTuple::Value; + +template requires CTTuple::Type> struct TTupleElementSize : TConstant::Type::ElementSize> { }; -template requires TIsTTuple::Type>::Value +template requires CTTuple::Type> struct TTupleElementType { using Type = typename TCopyCVRef::Type, typename TRemoveCVRef::Type::template TElementType::Type>::Type; }; -template requires TIsTTuple::Type>::Value +template requires CTTuple::Type> struct TTupleElementIndex : TupleType::template TElementIndex { }; template @@ -540,10 +546,10 @@ struct TTupleVisitImpl> NAMESPACE_PRIVATE_END -template requires (true && ... && (TIsTTuple::Type>::Value)) +template requires (true && ... && (CTTuple::Type>)) struct TTupleCatResult { using Type = typename NAMESPACE_PRIVATE::TTupleCatResultImpl::Type..., NAMESPACE_PRIVATE::FTupleEndFlag>::Type; }; -template requires (true && ... && (TIsTTuple::Type>::Value)) +template requires (true && ... && (CTTuple::Type>)) constexpr auto TupleCat(TTupleTypes&&... Args) { using R = typename TTupleCatResult::Type; diff --git a/Redcraft.Utility/Source/Public/Templates/TypeHash.h b/Redcraft.Utility/Source/Public/Templates/TypeHash.h index 9805a14..3150ec0 100644 --- a/Redcraft.Utility/Source/Public/Templates/TypeHash.h +++ b/Redcraft.Utility/Source/Public/Templates/TypeHash.h @@ -1,7 +1,6 @@ #pragma once #include "CoreTypes.h" -#include "Concepts/Same.h" #include "Templates/Utility.h" #include "TypeTraits/PrimaryType.h" #include "TypeTraits/Miscellaneous.h" diff --git a/Redcraft.Utility/Source/Public/Templates/Utility.h b/Redcraft.Utility/Source/Public/Templates/Utility.h index 21905f2..d8ad1ed 100644 --- a/Redcraft.Utility/Source/Public/Templates/Utility.h +++ b/Redcraft.Utility/Source/Public/Templates/Utility.h @@ -77,7 +77,7 @@ constexpr void Swap(T& A, T& B) } } -template requires CMoveConstructible && CAssignable +template requires CMoveConstructible && CAssignableFrom constexpr T Exchange(T& A, U&& B) { T Temp = MoveTemp(A); diff --git a/Redcraft.Utility/Source/Public/Templates/Variant.h b/Redcraft.Utility/Source/Public/Templates/Variant.h index ea11144..a8d24e4 100644 --- a/Redcraft.Utility/Source/Public/Templates/Variant.h +++ b/Redcraft.Utility/Source/Public/Templates/Variant.h @@ -49,7 +49,7 @@ struct TVariantSelectedType; template struct TVariantSelectedType { - using TypeAlternativeA = typename TConditional, U, void>::Type; + using TypeAlternativeA = typename TConditional, U, void>::Type; using TypeAlternativeB = typename TVariantSelectedType::Type; using Type = typename TConditional::Type, void>, TypeAlternativeB, @@ -103,7 +103,7 @@ struct TVariant } template requires (I < AlternativeSize) - && CConstructible::Type, ArgTypes...> + && CConstructibleFrom::Type, ArgTypes...> constexpr explicit TVariant(TInPlaceIndex, ArgTypes&&... Args) : TypeIndex(I) { @@ -112,13 +112,13 @@ struct TVariant } template requires (TAlternativeIndex::Value != INDEX_NONE) - && CConstructible::Value>::Type, ArgTypes...> + && CConstructibleFrom::Value>::Type, ArgTypes...> constexpr explicit TVariant(TInPlaceType, ArgTypes&&... Args) : TVariant(InPlaceIndex::Value>, Forward(Args)...) { } template requires NAMESPACE_PRIVATE::TVariantSelectedType::Type, Types...>::Value - && (!TIsTInPlaceType::Type>::Value) && (!TIsTInPlaceIndex::Type>::Value) + && (!CTInPlaceType::Type>) && (!CTInPlaceIndex::Type>) && (!CSameAs::Type, TVariant>) constexpr TVariant(T&& InValue) : TVariant(InPlaceType::Type, Types...>::Type>, Forward(InValue)) { } @@ -187,7 +187,7 @@ struct TVariant } template requires (I < AlternativeSize) - && CConstructible::Type, ArgTypes...> + && CConstructibleFrom::Type, ArgTypes...> constexpr typename TAlternativeType::Type& Emplace(ArgTypes&&... Args) { Reset(); @@ -200,7 +200,7 @@ struct TVariant } template requires (TAlternativeIndex::Value != INDEX_NONE) - && CConstructible::Value>::Type, ArgTypes...> + && CConstructibleFrom::Value>::Type, ArgTypes...> constexpr T& Emplace(ArgTypes&&... Args) { return Emplace::Value>(Forward(Args)...); @@ -319,7 +319,7 @@ struct TVariant return HashCombine(GetTypeHash(GetIndex()), HashImpl[GetIndex()](&Value)); } - constexpr void Swap(TVariant& InValue) requires (true && ... && (CMoveConstructible && TIsSwappable::Value)) + constexpr void Swap(TVariant& InValue) requires (true && ... && (CMoveConstructible && CSwappable)) { if (!IsValid() && !InValue.IsValid()) return; @@ -409,16 +409,22 @@ constexpr bool operator==(const TVariant& LHS, FInvalid) return !LHS.IsValid(); } +NAMESPACE_PRIVATE_BEGIN + template struct TIsTVariant : FFalse { }; template struct TIsTVariant> : FTrue { }; -template requires TIsTVariant::Type>::Value +NAMESPACE_PRIVATE_END + +template concept CTVariant = NAMESPACE_PRIVATE::TIsTVariant::Value; + +template requires CTVariant::Type> struct TVariantAlternativeSize : TConstant { }; -template requires TIsTVariant::Type>::Value +template requires CTVariant::Type> struct TVariantAlternativeType { using Type = typename TCopyCV::Type, typename TRemoveCVRef::Type::template TAlternativeType::Type>::Type; }; -template requires TIsTVariant::Type>::Value +template requires CTVariant::Type> struct TVariantAlternativeIndex : VariantType::template TAlternativeIndex { }; NAMESPACE_MODULE_END(Utility) diff --git a/Redcraft.Utility/Source/Public/Testing/ConceptsTesting.h b/Redcraft.Utility/Source/Public/Testing/ConceptsTesting.h deleted file mode 100644 index 4f865f5..0000000 --- a/Redcraft.Utility/Source/Public/Testing/ConceptsTesting.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "CoreTypes.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -NAMESPACE_BEGIN(Testing) - -REDCRAFTUTILITY_API void TestConcepts(); - -NAMESPACE_END(Testing) - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h b/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h index 86c9d22..15c26e3 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h @@ -13,32 +13,34 @@ NAMESPACE_MODULE_BEGIN(Utility) // Assume that all operands of bitwise operations have the same size -// This type traits is allowed to be specialised. -template struct TIsZeroConstructible : TBoolConstant && (CEnum || CArithmetic || CPointer)> { }; - -// This type traits is allowed to be specialised. +// Specialize these template classes for user-defined types +template struct TIsZeroConstructible; template struct TIsBitwiseConstructible; +template struct TIsBitwiseRelocatable; +template struct TIsBitwiseComparable; -template struct TIsBitwiseConstructible< T, const U> : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible< T, volatile U> : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible< T, const volatile U> : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible< volatile T, U> : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible< volatile T, const U> : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible< volatile T, volatile U> : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible< volatile T, const volatile U> : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; -template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; +// Normal use of these concepts +template concept CZeroConstructible = TIsZeroConstructible::Value; +template concept CBitwiseConstructible = TIsBitwiseConstructible::Value; +template concept CBitwiseRelocatable = TIsBitwiseRelocatable::Value; +template concept CBitwiseComparable = TIsBitwiseComparable::Value; -template struct TIsBitwiseConstructible : TBoolConstant> { }; +// Default constructible enum, arithmetic and pointer are zero constructible +template struct TIsZeroConstructible : TBoolConstant && (CEnum || CArithmetic || CPointer)> { }; +// Constructing a const T is the same as constructing a T +template struct TIsZeroConstructible : TIsZeroConstructible { }; + +// T can always be bitwise constructed from itself if it is trivially copy constructible template struct TIsBitwiseConstructible : TBoolConstant ? CTriviallyCopyConstructible : false> { }; +// Constructing a const T is the same as constructing a T +template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; + +// Const pointers can be bitwise constructed from non-const pointers +template struct TIsBitwiseConstructible : FTrue { }; + +// Unsigned types can be bitwise converted to their signed equivalents, and vice versa template <> struct TIsBitwiseConstructible : FTrue { }; template <> struct TIsBitwiseConstructible< int8, uint8> : FTrue { }; template <> struct TIsBitwiseConstructible : FTrue { }; @@ -48,32 +50,19 @@ template <> struct TIsBitwiseConstructible< int32, uint32> : FTrue { }; template <> struct TIsBitwiseConstructible : FTrue { }; template <> struct TIsBitwiseConstructible< int64, uint64> : FTrue { }; -// It is usually only necessary to specialize TIsBitwiseConstructible and not recommended to specialize TIsBitwiseRelocatable. -template struct TIsBitwiseRelocatable; +// WARNING: T is bitwise relocatable from itself by default +// T is bitwise relocatable from U, if U is trivially destructible and can be constructed bitwise to T +template struct TIsBitwiseRelocatable : TBoolConstant ? true : CTriviallyDestructible && CBitwiseConstructible> { }; -template struct TIsBitwiseRelocatable< T, const U> : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable< T, volatile U> : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable< T, const volatile U> : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable< volatile T, U> : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable< volatile T, const U> : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable< volatile T, volatile U> : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable< volatile T, const volatile U> : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; +// Constructing a const T is the same as constructing a T +template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; -template struct TIsBitwiseRelocatable : TBoolConstant> { }; - -template struct TIsBitwiseRelocatable : TBoolConstant::Value && CTriviallyDestructible> { }; - -// This type traits is allowed to be specialised. +// Enum, arithmetic and pointer are zero constructible template struct TIsBitwiseComparable : TBoolConstant || CArithmetic || CPointer> { }; +// Constructing a const T is the same as constructing a T +template struct TIsBitwiseComparable : TIsBitwiseComparable { }; + NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/TypeTraits/Common.h b/Redcraft.Utility/Source/Public/TypeTraits/Common.h index 80778a6..e505079 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/Common.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/Common.h @@ -1,7 +1,7 @@ #pragma once #include "CoreTypes.h" -#include "TypeTraits/HelperClasses.h" +#include "TypeTraits/Miscellaneous.h" #include @@ -24,6 +24,31 @@ NAMESPACE_PRIVATE_END template struct TCommonType : TConditional, NAMESPACE_PRIVATE::TCommonType, NAMESPACE_PRIVATE::FNoopStruct>::Type { }; template struct TCommonReference : TConditional, NAMESPACE_PRIVATE::TCommonReference, NAMESPACE_PRIVATE::FNoopStruct>::Type { }; +template +concept CCommonReferenceWith = + requires + { + typename TCommonReference::Type; + typename TCommonReference::Type; + } && + CSameAs::Type, typename TCommonReference::Type> && + CConvertibleTo::Type>&& + CConvertibleTo::Type>; + +template +concept CCommonWith = + requires + { + typename TCommonType::Type; + typename TCommonType::Type; + requires CSameAs::Type, typename TCommonType::Type>; + static_cast::Type>(DeclVal()); + static_cast::Type>(DeclVal()); + } && + CCommonReferenceWith && + CCommonReferenceWith::Type&, typename TCommonReference::Type> && + CSameAs::Type, typename TCommonReference::Type>; + NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Concepts/Comparable.h b/Redcraft.Utility/Source/Public/TypeTraits/Comparable.h similarity index 84% rename from Redcraft.Utility/Source/Public/Concepts/Comparable.h rename to Redcraft.Utility/Source/Public/TypeTraits/Comparable.h index 2d5fa09..b6ba151 100644 --- a/Redcraft.Utility/Source/Public/Concepts/Comparable.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/Comparable.h @@ -1,9 +1,9 @@ #pragma once #include "CoreTypes.h" -#include "Concepts/Common.h" -#include "TypeTraits/TypeTraits.h" -#include "Concepts/BooleanTestable.h" +#include "TypeTraits/Common.h" +#include "TypeTraits/Miscellaneous.h" +#include "TypeTraits/BooleanTestable.h" NAMESPACE_REDCRAFT_BEGIN NAMESPACE_MODULE_BEGIN(Redcraft) @@ -11,7 +11,7 @@ NAMESPACE_MODULE_BEGIN(Utility) template concept CWeaklyEqualityComparableWith = - requires(const TRemoveReference::Type& A, const TRemoveReference::Type& B) + requires(const typename TRemoveReference::Type& A, const typename TRemoveReference::Type& B) { { A == B } -> CBooleanTestable; { A != B } -> CBooleanTestable; @@ -32,7 +32,7 @@ concept CEqualityComparableWith = template concept CPartiallyOrderedWith = - requires(const TRemoveReference::Type& A, const TRemoveReference::Type& B) + requires(const typename TRemoveReference::Type& A, const typename TRemoveReference::Type& B) { { A < B } -> CBooleanTestable; { A > B } -> CBooleanTestable; diff --git a/Redcraft.Utility/Source/Public/TypeTraits/InPlaceSpecialization.h b/Redcraft.Utility/Source/Public/TypeTraits/InPlaceSpecialization.h index 30b2667..10a0bac 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/InPlaceSpecialization.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/InPlaceSpecialization.h @@ -7,12 +7,19 @@ NAMESPACE_REDCRAFT_BEGIN NAMESPACE_MODULE_BEGIN(Redcraft) NAMESPACE_MODULE_BEGIN(Utility) +NAMESPACE_PRIVATE_BEGIN + template struct TIsTInPlaceType : FFalse { }; template struct TIsTInPlaceType> : FTrue { }; template struct TIsTInPlaceIndex : FFalse { }; template struct TIsTInPlaceIndex> : FTrue { }; +NAMESPACE_PRIVATE_END + +template concept CTInPlaceType = NAMESPACE_PRIVATE::TIsTInPlaceType::Value; +template concept CTInPlaceIndex = NAMESPACE_PRIVATE::TIsTInPlaceIndex::Value; + NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/TypeTraits/Miscellaneous.h b/Redcraft.Utility/Source/Public/TypeTraits/Miscellaneous.h index 987c7ad..218b2cf 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/Miscellaneous.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/Miscellaneous.h @@ -51,6 +51,7 @@ template struct TEnableIf { using Type = template struct TConditional { using Type = NAMESPACE_STD::conditional_t; }; template struct TUnderlyingType { using Type = NAMESPACE_STD::underlying_type_t; }; template struct TVoid { using Type = void; }; +template struct TIdentity { using Type = T; }; NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) diff --git a/Redcraft.Utility/Source/Public/Concepts/Objects.h b/Redcraft.Utility/Source/Public/TypeTraits/Object.h similarity index 63% rename from Redcraft.Utility/Source/Public/Concepts/Objects.h rename to Redcraft.Utility/Source/Public/TypeTraits/Object.h index c4c60c6..92ea2e3 100644 --- a/Redcraft.Utility/Source/Public/Concepts/Objects.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/Object.h @@ -1,11 +1,10 @@ #pragma once #include "CoreTypes.h" -#include "Concepts/Swappable.h" -#include "Concepts/Assignable.h" -#include "Concepts/Comparable.h" -#include "TypeTraits/TypeTraits.h" -#include "Concepts/Constructible.h" +#include "TypeTraits/Swappable.h" +#include "TypeTraits/Comparable.h" +#include "TypeTraits/CompositeType.h" +#include "TypeTraits/SupportedOperations.h" NAMESPACE_REDCRAFT_BEGIN NAMESPACE_MODULE_BEGIN(Redcraft) @@ -15,18 +14,16 @@ template concept CMovable = CObject && CMoveConstructible && - CAssignableFrom && + CMoveAssignable && CSwappable; template concept CCopyable = CMovable && CCopyConstructible && - CAssignableFrom && - CAssignableFrom && - CAssignableFrom; + CCopyAssignable; template -concept CSemiregular = CCopyable && CDefaultInitializable; +concept CSemiregular = CCopyable && CDefaultConstructible; template concept CRegular = CSemiregular && CEqualityComparable; diff --git a/Redcraft.Utility/Source/Public/TypeTraits/SupportedOperations.h b/Redcraft.Utility/Source/Public/TypeTraits/SupportedOperations.h index 19c01e9..bea9a15 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/SupportedOperations.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/SupportedOperations.h @@ -37,17 +37,17 @@ template concept CVirtualDestructible = CDestructible //template concept CNothrowMoveAssignable; //template concept CNothrowDestructible; -template concept CAssignable = NAMESPACE_STD::is_assignable_v; +template concept CAssignableFrom = NAMESPACE_STD::is_assignable_v; -template concept CTriviallyAssignable = CAssignable && NAMESPACE_STD::is_trivially_assignable_v; +template concept CTriviallyAssignableFrom = CAssignableFrom && NAMESPACE_STD::is_trivially_assignable_v; -//template concept CNothrowAssignable; +//template concept CNothrowAssignableFrom; -template concept CConstructible = NAMESPACE_STD::is_constructible_v; +template concept CConstructibleFrom = NAMESPACE_STD::is_constructible_v; -template concept CTriviallyConstructible = CConstructible && NAMESPACE_STD::is_trivially_constructible_v; +template concept CTriviallyConstructibleFrom = CConstructibleFrom && NAMESPACE_STD::is_trivially_constructible_v; -//template concept CNothrowConstructible; +//template concept CNothrowConstructibleFrom; NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) diff --git a/Redcraft.Utility/Source/Public/TypeTraits/Swappable.h b/Redcraft.Utility/Source/Public/TypeTraits/Swappable.h index 2e2817d..b61512c 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/Swappable.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/Swappable.h @@ -2,19 +2,17 @@ #include "CoreTypes.h" #include "Templates/Utility.h" -#include "TypeTraits/HelperClasses.h" +#include "TypeTraits/Common.h" NAMESPACE_REDCRAFT_BEGIN NAMESPACE_MODULE_BEGIN(Redcraft) NAMESPACE_MODULE_BEGIN(Utility) -NAMESPACE_PRIVATE_BEGIN - template -concept CSwappable = requires(T & A, T & B) { Swap(A, B); }; +concept CSwappable = requires(T& A, T& B) { Swap(A, B); }; template -concept CSwappableWith = +concept CSwappableWith = CCommonReferenceWith && requires(T&& A, U&& B) { Swap(Forward(A), Forward(A)); @@ -23,13 +21,8 @@ concept CSwappableWith = Swap(Forward(B), Forward(A)); }; -NAMESPACE_PRIVATE_END - -template struct TIsSwappable : TBoolConstant> { }; -template struct TIsSwappableWith : TBoolConstant> { }; - -//template struct TIsNothrowSwappable; -//template struct TIsNothrowSwappableWith; +//template concept CNothrowSwappable; +//template concept CNothrowSwappableWith; NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) diff --git a/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h b/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h index 70265e6..bec9678 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h @@ -14,3 +14,5 @@ #include "TypeTraits/InPlaceSpecialization.h" #include "TypeTraits/BitwiseOperations.h" #include "TypeTraits/BooleanTestable.h" +#include "TypeTraits/Object.h" +#include "TypeTraits/Comparable.h"