refactor(typetraits): replaces template class type traits with concepts for TypeTraits/CompositeType.h
This commit is contained in:
parent
1dcd3dc3b3
commit
22fe906eda
@ -99,25 +99,6 @@ void TestConcepts()
|
||||
always_check(CCopyConstructible<FTestStructN>);
|
||||
always_check(!CCopyConstructible<FTestStructO>);
|
||||
|
||||
// BuiltinType.h
|
||||
|
||||
always_check(CIntegral<bool>);
|
||||
always_check(CIntegral<int32>);
|
||||
always_check(!CIntegral<float>);
|
||||
|
||||
always_check(CSignedIntegral<signed>);
|
||||
always_check(!CSignedIntegral<unsigned>);
|
||||
|
||||
always_check(!CUnsignedIntegral<signed>);
|
||||
always_check(CUnsignedIntegral<unsigned>);
|
||||
|
||||
always_check(!CNonBooleanIntegral<bool>);
|
||||
always_check(CNonBooleanIntegral<int32>);
|
||||
always_check(!CNonBooleanIntegral<float>);
|
||||
|
||||
always_check(!CFloatingPoint<int32>);
|
||||
always_check(CFloatingPoint<float>);
|
||||
|
||||
// BooleanTestable.h
|
||||
|
||||
always_check(CBooleanTestable<bool>);
|
||||
|
@ -120,43 +120,49 @@ void TestTypeTraits()
|
||||
|
||||
// CompositeType.h
|
||||
|
||||
always_check(!TIsFundamental<FTestStructA>::Value);
|
||||
always_check(TIsFundamental<int32>::Value);
|
||||
always_check(TIsFundamental<float>::Value);
|
||||
always_check(!TIsFundamental<int32*>::Value);
|
||||
always_check(TIsFundamental<void>::Value);
|
||||
always_check(!CFundamental<FTestStructA>);
|
||||
always_check(CFundamental<int32>);
|
||||
always_check(CFundamental<float>);
|
||||
always_check(!CFundamental<int32*>);
|
||||
always_check(CFundamental<void>);
|
||||
|
||||
always_check(!TIsArithmetic<FTestStructA>::Value);
|
||||
always_check(TIsArithmetic<int32>::Value);
|
||||
always_check(TIsArithmetic<float>::Value);
|
||||
always_check(!TIsArithmetic<int32*>::Value);
|
||||
always_check(!TIsArithmetic<void>::Value);
|
||||
always_check(!CArithmetic<FTestStructA>);
|
||||
always_check(CArithmetic<int32>);
|
||||
always_check(CArithmetic<float>);
|
||||
always_check(!CArithmetic<int32*>);
|
||||
always_check(!CArithmetic<void>);
|
||||
|
||||
always_check(!TIsScalar<FTestStructA>::Value);
|
||||
always_check(TIsScalar<int32>::Value);
|
||||
always_check(TIsScalar<float>::Value);
|
||||
always_check(TIsScalar<int32*>::Value);
|
||||
always_check(!TIsScalar<void>::Value);
|
||||
always_check(!CScalar<FTestStructA>);
|
||||
always_check(CScalar<int32>);
|
||||
always_check(CScalar<float>);
|
||||
always_check(CScalar<int32*>);
|
||||
always_check(!CScalar<void>);
|
||||
|
||||
always_check(TIsObject<FTestStructA>::Value);
|
||||
always_check(!TIsObject<FTestStructA&>::Value);
|
||||
always_check(TIsObject<int32>::Value);
|
||||
always_check(TIsObject<int32*>::Value);
|
||||
always_check(!TIsObject<int32&>::Value);
|
||||
always_check(CObject<FTestStructA>);
|
||||
always_check(!CObject<FTestStructA&>);
|
||||
always_check(CObject<int32>);
|
||||
always_check(CObject<int32*>);
|
||||
always_check(!CObject<int32&>);
|
||||
|
||||
always_check(TIsCompound<FTestStructA>::Value);
|
||||
always_check(TIsCompound<FTestStructA&>::Value);
|
||||
always_check(!TIsCompound<int32>::Value);
|
||||
always_check(TIsCompound<int32*>::Value);
|
||||
always_check(TIsCompound<int32&>::Value);
|
||||
always_check(CCompound<FTestStructA>);
|
||||
always_check(CCompound<FTestStructA&>);
|
||||
always_check(!CCompound<int32>);
|
||||
always_check(CCompound<int32*>);
|
||||
always_check(CCompound<int32&>);
|
||||
|
||||
always_check(!TIsReference<int32>::Value);
|
||||
always_check(!TIsReference<int32*>::Value);
|
||||
always_check(TIsReference<int32&>::Value);
|
||||
always_check(TIsReference<int32&&>::Value);
|
||||
always_check(!CReference<int32>);
|
||||
always_check(!CReference<int32*>);
|
||||
always_check(CReference<int32&>);
|
||||
always_check(CReference<int32&&>);
|
||||
|
||||
always_check(!TIsMemberPointer<FTestStructA>::Value);
|
||||
always_check(TIsMemberPointer<int32(FTestStructA::*)>::Value);
|
||||
always_check(!CMemberPointer<FTestStructA>);
|
||||
always_check(CMemberPointer<int32(FTestStructA::*)>);
|
||||
|
||||
always_check(CSignedIntegral<signed>);
|
||||
always_check(!CSignedIntegral<unsigned>);
|
||||
|
||||
always_check(!CUnsignedIntegral<signed>);
|
||||
always_check(CUnsignedIntegral<unsigned>);
|
||||
|
||||
// TypeProperties.h
|
||||
|
||||
|
@ -7,10 +7,6 @@ NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
template <typename T> concept CSignedIntegral = CIntegral<T> && TIsSigned<T>::Value;
|
||||
template <typename T> concept CUnsignedIntegral = CIntegral<T> && TIsUnsigned<T>::Value;
|
||||
template <typename T> concept CNonBooleanIntegral = CIntegral<T> && !TIsSame<typename TRemoveCVRef<T>::Type, bool>::Value;
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
||||
|
@ -13,7 +13,7 @@ NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
template <typename T>
|
||||
concept CMovable =
|
||||
TIsObject<T>::Value &&
|
||||
CObject<T> &&
|
||||
CMoveConstructible<T> &&
|
||||
CAssignableFrom<T&, T> &&
|
||||
CSwappable<T>;
|
||||
|
@ -42,7 +42,7 @@ NAMESPACE_PRIVATE_BEGIN
|
||||
template <typename T>
|
||||
constexpr bool FunctionIsBound(const T& Func)
|
||||
{
|
||||
if constexpr (CPointer<T> || TIsMemberPointer<T>::Value || TIsTFunctionRef<T>::Value || TIsTFunction<T>::Value || TIsTUniqueFunction<T>::Value)
|
||||
if constexpr (CPointer<T> || CMemberPointer<T> || TIsTFunctionRef<T>::Value || TIsTFunction<T>::Value || TIsTUniqueFunction<T>::Value)
|
||||
{
|
||||
return !!Func;
|
||||
}
|
||||
@ -171,7 +171,7 @@ protected:
|
||||
Callable = [](StorageRef Storage, Types&&... Args) -> ResultType
|
||||
{
|
||||
using InvokeType = typename TConditional<
|
||||
TIsReference<CVRef>::Value,
|
||||
CReference<CVRef>,
|
||||
typename TCopyCVRef<CVRef, CallableType>::Type,
|
||||
typename TCopyCVRef<CVRef, CallableType>::Type&
|
||||
>::Type;
|
||||
|
@ -10,7 +10,7 @@ NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
template <typename ReferencedType> requires (TIsObject<ReferencedType>::Value || CFunction<ReferencedType>)
|
||||
template <typename ReferencedType> requires (CObject<ReferencedType> || CFunction<ReferencedType>)
|
||||
struct TReferenceWrapper
|
||||
{
|
||||
public:
|
||||
@ -61,7 +61,7 @@ private:
|
||||
|
||||
ReferencedType* Pointer;
|
||||
|
||||
template <typename T> requires (TIsObject<T>::Value || CFunction<T>) friend struct TReferenceWrapper;
|
||||
template <typename T> requires (CObject<T> || CFunction<T>) friend struct TReferenceWrapper;
|
||||
|
||||
// Optimize TOptional with these hacking
|
||||
constexpr TReferenceWrapper(FInvalid) : Pointer(nullptr) { };
|
||||
|
@ -88,13 +88,13 @@ constexpr T Exchange(T& A, U&& B)
|
||||
template <typename T>
|
||||
constexpr T&& DeclVal();
|
||||
|
||||
template <typename T> requires TIsObject<T>::Value
|
||||
template <typename T> requires CObject<T>
|
||||
constexpr T* AddressOf(T& Object)
|
||||
{
|
||||
return reinterpret_cast<T*>(&const_cast<char&>(reinterpret_cast<const volatile char&>(Object)));
|
||||
}
|
||||
|
||||
template <typename T> requires (!TIsObject<T>::Value)
|
||||
template <typename T> requires (!CObject<T>)
|
||||
constexpr T* AddressOf(T& Object)
|
||||
{
|
||||
return &Object;
|
||||
|
@ -14,7 +14,7 @@ NAMESPACE_MODULE_BEGIN(Utility)
|
||||
// Assume that all operands of bitwise operations have the same size
|
||||
|
||||
// This type traits is allowed to be specialised.
|
||||
template <typename T> struct TIsZeroConstructible : TBoolConstant<TIsDefaultConstructible<T>::Value && (CEnum<T> || TIsArithmetic<T>::Value || CPointer<T>)> { };
|
||||
template <typename T> struct TIsZeroConstructible : TBoolConstant<TIsDefaultConstructible<T>::Value && (CEnum<T> || CArithmetic<T> || CPointer<T>)> { };
|
||||
|
||||
// This type traits is allowed to be specialised.
|
||||
template <typename T, typename U> struct TIsBitwiseConstructible;
|
||||
@ -67,12 +67,12 @@ template <typename T, typename U> struct TIsBitwiseRelocatable<const volatile T,
|
||||
template <typename T, typename U> struct TIsBitwiseRelocatable<const volatile T, volatile U> : TIsBitwiseRelocatable<T, U> { };
|
||||
template <typename T, typename U> struct TIsBitwiseRelocatable<const volatile T, const volatile U> : TIsBitwiseRelocatable<T, U> { };
|
||||
|
||||
template <typename T> struct TIsBitwiseRelocatable<T, T> : TBoolConstant<TIsObject<T>::Value> { };
|
||||
template <typename T> struct TIsBitwiseRelocatable<T, T> : TBoolConstant<CObject<T>> { };
|
||||
|
||||
template <typename T, typename U> struct TIsBitwiseRelocatable : TBoolConstant<TIsBitwiseConstructible<T, U>::Value && TIsTriviallyDestructible<U>::Value> { };
|
||||
|
||||
// This type traits is allowed to be specialised.
|
||||
template <typename T> struct TIsBitwiseComparable : TBoolConstant<CEnum<T> || TIsArithmetic<T>::Value || CPointer<T>> { };
|
||||
template <typename T> struct TIsBitwiseComparable : TBoolConstant<CEnum<T> || CArithmetic<T> || CPointer<T>> { };
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
|
@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "TypeTraits/HelperClasses.h"
|
||||
#include "TypeTraits/PrimaryType.h"
|
||||
#include "TypeTraits/TypeProperties.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
@ -9,13 +10,16 @@ NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
template <typename T> struct TIsReference : TBoolConstant<NAMESPACE_STD::is_reference_v<T>> { };
|
||||
template <typename T> struct TIsArithmetic : TBoolConstant<NAMESPACE_STD::is_arithmetic_v<T>> { };
|
||||
template <typename T> struct TIsFundamental : TBoolConstant<NAMESPACE_STD::is_fundamental_v<T>> { };
|
||||
template <typename T> struct TIsObject : TBoolConstant<NAMESPACE_STD::is_object_v<T>> { };
|
||||
template <typename T> struct TIsScalar : TBoolConstant<NAMESPACE_STD::is_scalar_v<T>> { };
|
||||
template <typename T> struct TIsCompound : TBoolConstant<NAMESPACE_STD::is_compound_v<T>> { };
|
||||
template <typename T> struct TIsMemberPointer : TBoolConstant<NAMESPACE_STD::is_member_pointer_v<T>> { };
|
||||
template <typename T> concept CReference = NAMESPACE_STD::is_reference_v<T>;
|
||||
template <typename T> concept CArithmetic = NAMESPACE_STD::is_arithmetic_v<T>;
|
||||
template <typename T> concept CFundamental = NAMESPACE_STD::is_fundamental_v<T>;
|
||||
template <typename T> concept CObject = NAMESPACE_STD::is_object_v<T>;
|
||||
template <typename T> concept CScalar = NAMESPACE_STD::is_scalar_v<T>;
|
||||
template <typename T> concept CCompound = NAMESPACE_STD::is_compound_v<T>;
|
||||
template <typename T> concept CMemberPointer = NAMESPACE_STD::is_member_pointer_v<T>;
|
||||
|
||||
template <typename T> concept CSignedIntegral = CIntegral<T> && TIsSigned<T>::Value;
|
||||
template <typename T> concept CUnsignedIntegral = CIntegral<T> && TIsUnsigned<T>::Value;
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "TypeTraits/HelperClasses.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user