diff --git a/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp b/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp index a2a78e1..5eecc02 100644 --- a/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/ConceptsTesting.cpp @@ -114,6 +114,75 @@ void TestConcepts() always_check(!CFloatingPoint); always_check(CFloatingPoint); + // BooleanTestable.h + + always_check(CBooleanTestable); + always_check(CBooleanTestable); + always_check(CBooleanTestable); + always_check(!CBooleanTestable); + + // Assignable.h + + always_check((CAssignableFrom)); + always_check((CAssignableFrom)); + always_check((CAssignableFrom)); + always_check(!(CAssignableFrom)); + always_check(!(CAssignableFrom)); + + // 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_MODULE_END(Utility) diff --git a/Redcraft.Utility/Source/Public/Concepts/Assignable.h b/Redcraft.Utility/Source/Public/Concepts/Assignable.h new file mode 100644 index 0000000..8b37a93 --- /dev/null +++ b/Redcraft.Utility/Source/Public/Concepts/Assignable.h @@ -0,0 +1,23 @@ +#pragma once + +#include "CoreTypes.h" +#include "Concepts/Common.h" +#include "Templates/Templates.h" +#include "TypeTraits/TypeTraits.h" + +NAMESPACE_REDCRAFT_BEGIN +NAMESPACE_MODULE_BEGIN(Redcraft) +NAMESPACE_MODULE_BEGIN(Utility) + +template +concept CAssignableFrom = + TIsLValueReference::Value && + 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 new file mode 100644 index 0000000..69073b4 --- /dev/null +++ b/Redcraft.Utility/Source/Public/Concepts/BooleanTestable.h @@ -0,0 +1,18 @@ +#pragma once + +#include "CoreTypes.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 CBooleanTestable = CConvertibleTo && + requires(T && B) { { !Forward(B) } -> CConvertibleTo; }; + +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 new file mode 100644 index 0000000..07614b5 --- /dev/null +++ b/Redcraft.Utility/Source/Public/Concepts/Common.h @@ -0,0 +1,40 @@ +#pragma once + +#include "CoreTypes.h" +#include "Concepts/Same.h" +#include "Templates/Templates.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/Comparable.h b/Redcraft.Utility/Source/Public/Concepts/Comparable.h new file mode 100644 index 0000000..d23340f --- /dev/null +++ b/Redcraft.Utility/Source/Public/Concepts/Comparable.h @@ -0,0 +1,59 @@ +#pragma once + +#include "CoreTypes.h" +#include "Concepts/Common.h" +#include "TypeTraits/TypeTraits.h" +#include "Concepts/BooleanTestable.h" + +NAMESPACE_REDCRAFT_BEGIN +NAMESPACE_MODULE_BEGIN(Redcraft) +NAMESPACE_MODULE_BEGIN(Utility) + +template +concept CWeaklyEqualityComparableWith = + requires(const TRemoveReference::Type & A, const TRemoveReference::Type & B) + { + { A == B } -> CBooleanTestable; + { A != B } -> CBooleanTestable; + { B == A } -> CBooleanTestable; + { B != A } -> CBooleanTestable; + }; + +template +concept CEqualityComparable = CWeaklyEqualityComparableWith; + +template +concept CEqualityComparableWith = + CEqualityComparable && + CEqualityComparable && + CWeaklyEqualityComparableWith && + CCommonReferenceWith::Type&, const typename TRemoveReference::Type&> && + CEqualityComparable::Type&, const typename TRemoveReference::Type&>::Type>; + +template +concept CPartiallyOrderedWith = + requires(const TRemoveReference::Type& A, const TRemoveReference::Type& B) + { + { A < B } -> CBooleanTestable; + { A > B } -> CBooleanTestable; + { A <= B } -> CBooleanTestable; + { A >= B } -> CBooleanTestable; + { B < A } -> CBooleanTestable; + { B > A } -> CBooleanTestable; + { B <= A } -> CBooleanTestable; + { B >= A } -> CBooleanTestable; + }; + +template +concept CTotallyOrdered = CEqualityComparable && CPartiallyOrderedWith; + +template +concept CTotallyOrderedWith = + CTotallyOrdered && CTotallyOrdered && + CPartiallyOrderedWith && + CEqualityComparableWith && + CTotallyOrdered::Type&, const typename TRemoveReference::Type&>::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 index c01449f..57c389f 100644 --- a/Redcraft.Utility/Source/Public/Concepts/Concepts.h +++ b/Redcraft.Utility/Source/Public/Concepts/Concepts.h @@ -3,25 +3,16 @@ #include "CoreTypes.h" #include "Concepts/Same.h" #include "Concepts/Derived.h" +#include "Concepts/Objects.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" -//template concept CBooleanTestable; // Prerequisites: Forward -//template concept CMovable; // Prerequisites: CAssignableFrom -//template concept CCopyable; // Prerequisites: CAssignableFrom -//template concept CSemiregular; // Prerequisites: CCopyable -//template concept CRegular; // Prerequisites: CEqualityComparable - -//template concept CAssignableFrom; // Prerequisites: Forward -//template concept CEqualityComparable; // Prerequisites: CBooleanTestable -//template concept CEqualityComparableWith; // Prerequisites: CBooleanTestable -//template concept CTotallyOrdered; // Prerequisites: CBooleanTestable -//template concept CTotallyOrderedWith; // Prerequisites: CBooleanTestable - -//template concept CCommonWith; // Prerequisites: Declval -//template concept CCommonReferenceWith; // Prerequisites: Declval //template concept CInvocable; // Prerequisites: Invoke, Forward //template concept CRegularInvocable; // Prerequisites: Invoke, Forward //template concept CPredicate; // Prerequisites: CBooleanTestable, CRegularInvocable diff --git a/Redcraft.Utility/Source/Public/Concepts/Constructible.h b/Redcraft.Utility/Source/Public/Concepts/Constructible.h index 74d3158..edbc815 100644 --- a/Redcraft.Utility/Source/Public/Concepts/Constructible.h +++ b/Redcraft.Utility/Source/Public/Concepts/Constructible.h @@ -1,8 +1,9 @@ #pragma once #include "CoreTypes.h" -#include "TypeTraits/TypeTraits.h" #include "Concepts/Convertible.h" +#include "TypeTraits/TypeTraits.h" +#include "Concepts/Destructible.h" #include diff --git a/Redcraft.Utility/Source/Public/Concepts/Objects.h b/Redcraft.Utility/Source/Public/Concepts/Objects.h new file mode 100644 index 0000000..f430bc9 --- /dev/null +++ b/Redcraft.Utility/Source/Public/Concepts/Objects.h @@ -0,0 +1,36 @@ +#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" + +NAMESPACE_REDCRAFT_BEGIN +NAMESPACE_MODULE_BEGIN(Redcraft) +NAMESPACE_MODULE_BEGIN(Utility) + +template +concept CMovable = + TIsObject::Value && + CMoveConstructible && + CAssignableFrom && + CSwappable; + +template +concept CCopyable = CMovable && + CCopyConstructible && + CAssignableFrom && + CAssignableFrom && + CAssignableFrom; + +template +concept CSemiregular = CCopyable && CDefaultInitializable; + +template +concept CRegular = CSemiregular && CEqualityComparable; + +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 new file mode 100644 index 0000000..93fd8d0 --- /dev/null +++ b/Redcraft.Utility/Source/Public/Concepts/Swappable.h @@ -0,0 +1,27 @@ +#pragma once + +#include "CoreTypes.h" +#include "Concepts/Common.h" +#include "Templates/Templates.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