From c69ed3b9e16bc810b3d7932615f52645b85fcf8b Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Sat, 19 Mar 2022 13:27:37 +0800 Subject: [PATCH] feat(typetraits): complete type traits for bitwise operations --- .../Public/TypeTraits/BitwiseOperations.h | 69 +++++++++++++++++++ .../Source/Public/TypeTraits/TypeTraits.h | 1 + 2 files changed, 70 insertions(+) create mode 100644 Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h diff --git a/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h b/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h new file mode 100644 index 0000000..ddaa090 --- /dev/null +++ b/Redcraft.Utility/Source/Public/TypeTraits/BitwiseOperations.h @@ -0,0 +1,69 @@ +#pragma once + +#include "CoreTypes.h" +#include "TypeTraits/PrimaryType.h" +#include "TypeTraits/HelperClasses.h" +#include "TypeTraits/CompositeType.h" +#include "TypeTraits/Miscellaneous.h" +#include "TypeTraits/SupportedOperations.h" + +NAMESPACE_REDCRAFT_BEGIN +NAMESPACE_MODULE_BEGIN(Redcraft) +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::Value || TIsArithmetic::Value || TIsPointer::Value> { }; + +// This type traits is allowed to be specialised. +template struct TIsBitwiseConstructible; + +template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; +template struct TIsBitwiseConstructible : TIsBitwiseConstructible { }; +template struct TIsBitwiseConstructible : 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 : TIsTriviallyCopyConstructible { }; + +template struct TIsBitwiseConstructible : TBoolConstant::Type, typename TRemoveCV::Type>::Value> { }; + +template struct TIsBitwiseConstructible : FFalse { }; + +template <> struct TIsBitwiseConstructible : FTrue { }; +template <> struct TIsBitwiseConstructible< int8, uint8> : FTrue { }; +template <> struct TIsBitwiseConstructible : FTrue { }; +template <> struct TIsBitwiseConstructible< int16, uint16> : FTrue { }; +template <> struct TIsBitwiseConstructible : FTrue { }; +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; + +template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; +template struct TIsBitwiseRelocatable : TIsBitwiseRelocatable { }; +template struct TIsBitwiseRelocatable : 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 : FTrue { }; + +template struct TIsBitwiseRelocatable : TBoolConstant::Value && TIsTriviallyDestructible::Value> { }; + +// This type traits is allowed to be specialised. +template struct TIsBitwiseComparable : TBoolConstant::Value || TIsArithmetic::Value || TIsPointer::Value> { }; + +NAMESPACE_MODULE_END(Utility) +NAMESPACE_MODULE_END(Redcraft) +NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h b/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h index 18e727e..1d8d0e9 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h @@ -11,3 +11,4 @@ #include "TypeTraits/Common.h" #include "TypeTraits/CopyQualifiers.h" #include "TypeTraits/InPlaceSpecialization.h" +#include "TypeTraits/BitwiseOperations.h"