From 1bff879a0b78ed939beee2d5e85a06a12a3b8d85 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Thu, 17 Mar 2022 09:22:48 +0800 Subject: [PATCH] style(*): move some constants and placeholders to CoreMiscDefines.h --- Redcraft.Utility/Source/Public/CoreTypes.h | 2 +- .../Source/Public/Miscellaneous/CoreDefines.h | 11 ------ .../Public/Miscellaneous/CoreMiscDefines.h | 30 ++++++++++++++++ .../Public/Miscellaneous/Placeholders.h | 36 ------------------- .../Source/Public/Miscellaneous/TypeInfo.h | 1 - .../Source/Public/Templates/Variant.h | 24 ++++++------- .../Public/TypeTraits/InPlaceSpecialization.h | 18 ++++++++++ .../Source/Public/TypeTraits/TypeTraits.h | 1 + 8 files changed, 62 insertions(+), 61 deletions(-) create mode 100644 Redcraft.Utility/Source/Public/Miscellaneous/CoreMiscDefines.h delete mode 100644 Redcraft.Utility/Source/Public/Miscellaneous/Placeholders.h create mode 100644 Redcraft.Utility/Source/Public/TypeTraits/InPlaceSpecialization.h diff --git a/Redcraft.Utility/Source/Public/CoreTypes.h b/Redcraft.Utility/Source/Public/CoreTypes.h index c7342db..8492771 100644 --- a/Redcraft.Utility/Source/Public/CoreTypes.h +++ b/Redcraft.Utility/Source/Public/CoreTypes.h @@ -2,4 +2,4 @@ #include "Miscellaneous/Platform.h" #include "Miscellaneous/CoreDefines.h" -#include "Miscellaneous/Placeholders.h" +#include "Miscellaneous/CoreMiscDefines.h" diff --git a/Redcraft.Utility/Source/Public/Miscellaneous/CoreDefines.h b/Redcraft.Utility/Source/Public/Miscellaneous/CoreDefines.h index 67858b8..ce5b723 100644 --- a/Redcraft.Utility/Source/Public/Miscellaneous/CoreDefines.h +++ b/Redcraft.Utility/Source/Public/Miscellaneous/CoreDefines.h @@ -33,14 +33,3 @@ // Define the unnamed namespace #define NAMESPACE_UNNAMED_BEGIN namespace { #define NAMESPACE_UNNAMED_END } - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -enum { INDEX_NONE = -1 }; -enum { UNICODE_BOM = 0xfeff }; - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Miscellaneous/CoreMiscDefines.h b/Redcraft.Utility/Source/Public/Miscellaneous/CoreMiscDefines.h new file mode 100644 index 0000000..9cbdb52 --- /dev/null +++ b/Redcraft.Utility/Source/Public/Miscellaneous/CoreMiscDefines.h @@ -0,0 +1,30 @@ +#pragma once + +#include "Miscellaneous/CoreDefines.h" + +NAMESPACE_REDCRAFT_BEGIN +NAMESPACE_MODULE_BEGIN(Redcraft) +NAMESPACE_MODULE_BEGIN(Utility) + +constexpr size_t INDEX_NONE = -1; +constexpr WIDECHAR UNICODE_BOM = 0xfeff; + +struct FForceInit { explicit FForceInit() = default; }; +struct FNoInit { explicit FNoInit() = default; }; +struct FInvalid { explicit FInvalid() = default; }; +struct FInPlace { explicit FInPlace() = default; }; + +inline constexpr FForceInit ForceInit{ }; +inline constexpr FNoInit NoInit{ }; +inline constexpr FInvalid Invalid{ }; +inline constexpr FInPlace InPlace{ }; + +template struct TInPlaceType { explicit TInPlaceType() = default; }; +template struct TInPlaceIndex { explicit TInPlaceIndex() = default; }; + +template inline constexpr TInPlaceType InPlaceType{ }; +template inline constexpr TInPlaceIndex InPlaceIndex{ }; + +NAMESPACE_MODULE_END(Utility) +NAMESPACE_MODULE_END(Redcraft) +NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Miscellaneous/Placeholders.h b/Redcraft.Utility/Source/Public/Miscellaneous/Placeholders.h deleted file mode 100644 index 586d638..0000000 --- a/Redcraft.Utility/Source/Public/Miscellaneous/Placeholders.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "CoreTypes.h" -#include "TypeTraits/HelperClasses.h" - -NAMESPACE_REDCRAFT_BEGIN -NAMESPACE_MODULE_BEGIN(Redcraft) -NAMESPACE_MODULE_BEGIN(Utility) - -struct FForceInit { explicit FForceInit() = default; }; -inline constexpr FForceInit ForceInit{}; - -struct FNoInit { explicit FNoInit() = default; }; -inline constexpr FNoInit NoInit{}; - -struct FInvalid { explicit FInvalid() = default; }; -inline constexpr FInvalid Invalid{}; - -struct FInPlace { explicit FInPlace() = default; }; -inline constexpr FInPlace InPlace{}; - -template struct TInPlaceType { explicit TInPlaceType() = default; }; -template inline constexpr TInPlaceType InPlaceType{}; - -template struct TInPlaceIndex { explicit TInPlaceIndex() = default; }; -template inline constexpr TInPlaceIndex InPlaceIndex{}; - -template struct TIsInPlaceTypeSpecialization : FFalse { }; -template struct TIsInPlaceTypeSpecialization> : FTrue { }; - -template struct TIsInPlaceIndexSpecialization : FFalse { }; -template struct TIsInPlaceIndexSpecialization> : FTrue { }; - -NAMESPACE_MODULE_END(Utility) -NAMESPACE_MODULE_END(Redcraft) -NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Miscellaneous/TypeInfo.h b/Redcraft.Utility/Source/Public/Miscellaneous/TypeInfo.h index 4db6627..a25e012 100644 --- a/Redcraft.Utility/Source/Public/Miscellaneous/TypeInfo.h +++ b/Redcraft.Utility/Source/Public/Miscellaneous/TypeInfo.h @@ -2,7 +2,6 @@ #include "CoreTypes.h" #include "Miscellaneous/Compare.h" -#include "Miscellaneous/Placeholders.h" #include diff --git a/Redcraft.Utility/Source/Public/Templates/Variant.h b/Redcraft.Utility/Source/Public/Templates/Variant.h index 55c751b..a03db66 100644 --- a/Redcraft.Utility/Source/Public/Templates/Variant.h +++ b/Redcraft.Utility/Source/Public/Templates/Variant.h @@ -16,12 +16,12 @@ struct TVariantAlternativeIndex; template struct TVariantAlternativeIndex - : TConstant::Value ? 0 : (TVariantAlternativeIndex::Value == static_cast(INDEX_NONE) - ? static_cast(INDEX_NONE) : TVariantAlternativeIndex::Value + 1)> + : TConstant::Value ? 0 : (TVariantAlternativeIndex::Value == INDEX_NONE + ? INDEX_NONE : TVariantAlternativeIndex::Value + 1)> { }; template -struct TVariantAlternativeIndex : TConstant(INDEX_NONE)> { }; +struct TVariantAlternativeIndex : TConstant { }; template struct TVariantAlternativeType; @@ -225,20 +225,20 @@ struct TVariant template struct TAlternativeType : NAMESPACE_PRIVATE::TVariantAlternativeType { }; template struct TAlternativeIndex : NAMESPACE_PRIVATE::TVariantAlternativeIndex { }; - constexpr TVariant() : TypeIndex(static_cast(INDEX_NONE)) { }; + constexpr TVariant() : TypeIndex(INDEX_NONE) { }; constexpr TVariant(FInvalid) : TVariant() { }; constexpr TVariant(const TVariant& InValue) : TypeIndex(InValue.GetIndex()) { - if (GetIndex() != static_cast(INDEX_NONE)) FHelper::CopyConstructFuncs[InValue.GetIndex()](&Value, &InValue.Value); + if (GetIndex() != INDEX_NONE) FHelper::CopyConstructFuncs[InValue.GetIndex()](&Value, &InValue.Value); } constexpr TVariant(TVariant&& InValue) : TypeIndex(InValue.GetIndex()) { - if (GetIndex() != static_cast(INDEX_NONE)) FHelper::MoveConstructFuncs[InValue.GetIndex()](&Value, &InValue.Value); + if (GetIndex() != INDEX_NONE) FHelper::MoveConstructFuncs[InValue.GetIndex()](&Value, &InValue.Value); } template requires (I < FAlternativeSize::Value) @@ -250,7 +250,7 @@ struct TVariant new(&Value) SelectedType(Forward(Args)...); } - template requires (TAlternativeIndex::Value != static_cast(INDEX_NONE)) + template requires (TAlternativeIndex::Value != INDEX_NONE) && TIsConstructible::Value>::Type, ArgTypes...>::Value constexpr explicit TVariant(TInPlaceType, ArgTypes&&... Args) : TVariant(InPlaceIndex::Value>, Forward(Args)...) @@ -338,7 +338,7 @@ struct TVariant return *Result; } - template requires (TAlternativeIndex::Value != static_cast(INDEX_NONE)) + template requires (TAlternativeIndex::Value != INDEX_NONE) && TIsConstructible::Value>::Type, ArgTypes...>::Value constexpr T& Emplace(ArgTypes&&... Args) { @@ -346,8 +346,8 @@ struct TVariant } constexpr size_t GetIndex() const { return TypeIndex; } - constexpr bool IsValid() const { return GetIndex() != static_cast(INDEX_NONE); } - constexpr explicit operator bool() const { return GetIndex() != static_cast(INDEX_NONE); } + constexpr bool IsValid() const { return GetIndex() != INDEX_NONE; } + constexpr explicit operator bool() const { return GetIndex() != INDEX_NONE; } template constexpr bool HoldsAlternative() const { return IsValid() ? GetIndex() == I : false; } template constexpr bool HoldsAlternative() const { return IsValid() ? GetIndex() == TAlternativeIndex::Value : false; } @@ -433,11 +433,11 @@ struct TVariant constexpr void Reset() { - if (GetIndex() == static_cast(INDEX_NONE)) return; + if (GetIndex() == INDEX_NONE) return; FHelper::DestroyFuncs[GetIndex()](&Value); - TypeIndex = static_cast(INDEX_NONE); + TypeIndex = INDEX_NONE; } private: diff --git a/Redcraft.Utility/Source/Public/TypeTraits/InPlaceSpecialization.h b/Redcraft.Utility/Source/Public/TypeTraits/InPlaceSpecialization.h new file mode 100644 index 0000000..83fd117 --- /dev/null +++ b/Redcraft.Utility/Source/Public/TypeTraits/InPlaceSpecialization.h @@ -0,0 +1,18 @@ +#pragma once + +#include "CoreTypes.h" +#include "TypeTraits/HelperClasses.h" + +NAMESPACE_REDCRAFT_BEGIN +NAMESPACE_MODULE_BEGIN(Redcraft) +NAMESPACE_MODULE_BEGIN(Utility) + +template struct TIsInPlaceTypeSpecialization : FFalse { }; +template struct TIsInPlaceTypeSpecialization> : FTrue { }; + +template struct TIsInPlaceIndexSpecialization : FFalse { }; +template struct TIsInPlaceIndexSpecialization> : FTrue { }; + +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 8ed0163..18e727e 100644 --- a/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h +++ b/Redcraft.Utility/Source/Public/TypeTraits/TypeTraits.h @@ -10,3 +10,4 @@ #include "TypeTraits/Swappable.h" #include "TypeTraits/Common.h" #include "TypeTraits/CopyQualifiers.h" +#include "TypeTraits/InPlaceSpecialization.h"