style(*): move some constants and placeholders to CoreMiscDefines.h

This commit is contained in:
_Redstone_c_ 2022-03-17 09:22:48 +08:00
parent b10963d310
commit 1bff879a0b
8 changed files with 62 additions and 61 deletions

View File

@ -2,4 +2,4 @@
#include "Miscellaneous/Platform.h" #include "Miscellaneous/Platform.h"
#include "Miscellaneous/CoreDefines.h" #include "Miscellaneous/CoreDefines.h"
#include "Miscellaneous/Placeholders.h" #include "Miscellaneous/CoreMiscDefines.h"

View File

@ -33,14 +33,3 @@
// Define the unnamed namespace // Define the unnamed namespace
#define NAMESPACE_UNNAMED_BEGIN namespace { #define NAMESPACE_UNNAMED_BEGIN namespace {
#define NAMESPACE_UNNAMED_END } #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

View File

@ -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 <typename T> struct TInPlaceType { explicit TInPlaceType() = default; };
template <size_t I> struct TInPlaceIndex { explicit TInPlaceIndex() = default; };
template <typename T> inline constexpr TInPlaceType<T> InPlaceType{ };
template <size_t I> inline constexpr TInPlaceIndex<I> InPlaceIndex{ };
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)
NAMESPACE_REDCRAFT_END

View File

@ -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 <typename T> struct TInPlaceType { explicit TInPlaceType() = default; };
template <typename T> inline constexpr TInPlaceType<T> InPlaceType{};
template <size_t I> struct TInPlaceIndex { explicit TInPlaceIndex() = default; };
template <size_t I> inline constexpr TInPlaceIndex<I> InPlaceIndex{};
template <typename T> struct TIsInPlaceTypeSpecialization : FFalse { };
template <typename T> struct TIsInPlaceTypeSpecialization<TInPlaceType<T>> : FTrue { };
template <typename T> struct TIsInPlaceIndexSpecialization : FFalse { };
template <size_t I> struct TIsInPlaceIndexSpecialization<TInPlaceIndex<I>> : FTrue { };
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)
NAMESPACE_REDCRAFT_END

View File

@ -2,7 +2,6 @@
#include "CoreTypes.h" #include "CoreTypes.h"
#include "Miscellaneous/Compare.h" #include "Miscellaneous/Compare.h"
#include "Miscellaneous/Placeholders.h"
#include <typeinfo> #include <typeinfo>

View File

@ -16,12 +16,12 @@ struct TVariantAlternativeIndex;
template <typename T, typename U, typename... Types> template <typename T, typename U, typename... Types>
struct TVariantAlternativeIndex<T, U, Types...> struct TVariantAlternativeIndex<T, U, Types...>
: TConstant<size_t, TIsSame<T, U>::Value ? 0 : (TVariantAlternativeIndex<T, Types...>::Value == static_cast<size_t>(INDEX_NONE) : TConstant<size_t, TIsSame<T, U>::Value ? 0 : (TVariantAlternativeIndex<T, Types...>::Value == INDEX_NONE
? static_cast<size_t>(INDEX_NONE) : TVariantAlternativeIndex<T, Types...>::Value + 1)> ? INDEX_NONE : TVariantAlternativeIndex<T, Types...>::Value + 1)>
{ }; { };
template <typename T> template <typename T>
struct TVariantAlternativeIndex<T> : TConstant<size_t, static_cast<size_t>(INDEX_NONE)> { }; struct TVariantAlternativeIndex<T> : TConstant<size_t, INDEX_NONE> { };
template <size_t I, typename... Types> template <size_t I, typename... Types>
struct TVariantAlternativeType; struct TVariantAlternativeType;
@ -225,20 +225,20 @@ struct TVariant
template <size_t I> struct TAlternativeType : NAMESPACE_PRIVATE::TVariantAlternativeType<I, Types...> { }; template <size_t I> struct TAlternativeType : NAMESPACE_PRIVATE::TVariantAlternativeType<I, Types...> { };
template <typename T> struct TAlternativeIndex : NAMESPACE_PRIVATE::TVariantAlternativeIndex<T, Types...> { }; template <typename T> struct TAlternativeIndex : NAMESPACE_PRIVATE::TVariantAlternativeIndex<T, Types...> { };
constexpr TVariant() : TypeIndex(static_cast<size_t>(INDEX_NONE)) { }; constexpr TVariant() : TypeIndex(INDEX_NONE) { };
constexpr TVariant(FInvalid) : TVariant() { }; constexpr TVariant(FInvalid) : TVariant() { };
constexpr TVariant(const TVariant& InValue) constexpr TVariant(const TVariant& InValue)
: TypeIndex(InValue.GetIndex()) : TypeIndex(InValue.GetIndex())
{ {
if (GetIndex() != static_cast<size_t>(INDEX_NONE)) FHelper::CopyConstructFuncs[InValue.GetIndex()](&Value, &InValue.Value); if (GetIndex() != INDEX_NONE) FHelper::CopyConstructFuncs[InValue.GetIndex()](&Value, &InValue.Value);
} }
constexpr TVariant(TVariant&& InValue) constexpr TVariant(TVariant&& InValue)
: TypeIndex(InValue.GetIndex()) : TypeIndex(InValue.GetIndex())
{ {
if (GetIndex() != static_cast<size_t>(INDEX_NONE)) FHelper::MoveConstructFuncs[InValue.GetIndex()](&Value, &InValue.Value); if (GetIndex() != INDEX_NONE) FHelper::MoveConstructFuncs[InValue.GetIndex()](&Value, &InValue.Value);
} }
template<size_t I, typename... ArgTypes> requires (I < FAlternativeSize::Value) template<size_t I, typename... ArgTypes> requires (I < FAlternativeSize::Value)
@ -250,7 +250,7 @@ struct TVariant
new(&Value) SelectedType(Forward<ArgTypes>(Args)...); new(&Value) SelectedType(Forward<ArgTypes>(Args)...);
} }
template<typename T, typename... ArgTypes> requires (TAlternativeIndex<T>::Value != static_cast<size_t>(INDEX_NONE)) template<typename T, typename... ArgTypes> requires (TAlternativeIndex<T>::Value != INDEX_NONE)
&& TIsConstructible<typename TAlternativeType<TAlternativeIndex<T>::Value>::Type, ArgTypes...>::Value && TIsConstructible<typename TAlternativeType<TAlternativeIndex<T>::Value>::Type, ArgTypes...>::Value
constexpr explicit TVariant(TInPlaceType<T>, ArgTypes&&... Args) constexpr explicit TVariant(TInPlaceType<T>, ArgTypes&&... Args)
: TVariant(InPlaceIndex<TAlternativeIndex<T>::Value>, Forward<ArgTypes>(Args)...) : TVariant(InPlaceIndex<TAlternativeIndex<T>::Value>, Forward<ArgTypes>(Args)...)
@ -338,7 +338,7 @@ struct TVariant
return *Result; return *Result;
} }
template <typename T, typename... ArgTypes> requires (TAlternativeIndex<T>::Value != static_cast<size_t>(INDEX_NONE)) template <typename T, typename... ArgTypes> requires (TAlternativeIndex<T>::Value != INDEX_NONE)
&& TIsConstructible<typename TAlternativeType<TAlternativeIndex<T>::Value>::Type, ArgTypes...>::Value && TIsConstructible<typename TAlternativeType<TAlternativeIndex<T>::Value>::Type, ArgTypes...>::Value
constexpr T& Emplace(ArgTypes&&... Args) constexpr T& Emplace(ArgTypes&&... Args)
{ {
@ -346,8 +346,8 @@ struct TVariant
} }
constexpr size_t GetIndex() const { return TypeIndex; } constexpr size_t GetIndex() const { return TypeIndex; }
constexpr bool IsValid() const { return GetIndex() != static_cast<size_t>(INDEX_NONE); } constexpr bool IsValid() const { return GetIndex() != INDEX_NONE; }
constexpr explicit operator bool() const { return GetIndex() != static_cast<size_t>(INDEX_NONE); } constexpr explicit operator bool() const { return GetIndex() != INDEX_NONE; }
template <size_t I> constexpr bool HoldsAlternative() const { return IsValid() ? GetIndex() == I : false; } template <size_t I> constexpr bool HoldsAlternative() const { return IsValid() ? GetIndex() == I : false; }
template <typename T> constexpr bool HoldsAlternative() const { return IsValid() ? GetIndex() == TAlternativeIndex<T>::Value : false; } template <typename T> constexpr bool HoldsAlternative() const { return IsValid() ? GetIndex() == TAlternativeIndex<T>::Value : false; }
@ -433,11 +433,11 @@ struct TVariant
constexpr void Reset() constexpr void Reset()
{ {
if (GetIndex() == static_cast<size_t>(INDEX_NONE)) return; if (GetIndex() == INDEX_NONE) return;
FHelper::DestroyFuncs[GetIndex()](&Value); FHelper::DestroyFuncs[GetIndex()](&Value);
TypeIndex = static_cast<size_t>(INDEX_NONE); TypeIndex = INDEX_NONE;
} }
private: private:

View File

@ -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 <typename T> struct TIsInPlaceTypeSpecialization : FFalse { };
template <typename T> struct TIsInPlaceTypeSpecialization<TInPlaceType<T>> : FTrue { };
template <typename T> struct TIsInPlaceIndexSpecialization : FFalse { };
template <size_t I> struct TIsInPlaceIndexSpecialization<TInPlaceIndex<I>> : FTrue { };
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)
NAMESPACE_REDCRAFT_END

View File

@ -10,3 +10,4 @@
#include "TypeTraits/Swappable.h" #include "TypeTraits/Swappable.h"
#include "TypeTraits/Common.h" #include "TypeTraits/Common.h"
#include "TypeTraits/CopyQualifiers.h" #include "TypeTraits/CopyQualifiers.h"
#include "TypeTraits/InPlaceSpecialization.h"