style(templates): redefine placeholders such as ForceInit, InPlace, etc.
This commit is contained in:
parent
8a3b089648
commit
0b4cb1a9e0
@ -41,11 +41,6 @@ NAMESPACE_MODULE_BEGIN(Utility)
|
|||||||
enum { INDEX_NONE = -1 };
|
enum { INDEX_NONE = -1 };
|
||||||
enum { UNICODE_BOM = 0xfeff };
|
enum { UNICODE_BOM = 0xfeff };
|
||||||
|
|
||||||
enum EForceInit { ForceInit };
|
|
||||||
enum ENoInit { NoInit };
|
|
||||||
enum EInvalid { Invalid };
|
|
||||||
enum EInPlace { InPlace };
|
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
NAMESPACE_MODULE_END(Utility)
|
||||||
NAMESPACE_MODULE_END(Redcraft)
|
NAMESPACE_MODULE_END(Redcraft)
|
||||||
NAMESPACE_REDCRAFT_END
|
NAMESPACE_REDCRAFT_END
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Templates/Compare.h"
|
#include "Templates/Compare.h"
|
||||||
|
#include "Templates/Placeholders.h"
|
||||||
#include "Concepts/Comparable.h"
|
#include "Concepts/Comparable.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "Miscellaneous/AssertionMacros.h"
|
#include "Miscellaneous/AssertionMacros.h"
|
||||||
@ -19,17 +20,17 @@ public:
|
|||||||
|
|
||||||
constexpr TOptional() : bIsValid(false) { }
|
constexpr TOptional() : bIsValid(false) { }
|
||||||
|
|
||||||
constexpr TOptional(EInvalid) : TOptional() { }
|
constexpr TOptional(FInvalid) : TOptional() { }
|
||||||
|
|
||||||
template <typename... Types> requires TIsConstructible<OptionalType, Types...>::Value
|
template <typename... Types> requires TIsConstructible<OptionalType, Types...>::Value
|
||||||
constexpr explicit TOptional(EInPlace, Types&&... Args)
|
constexpr explicit TOptional(FInPlace, Types&&... Args)
|
||||||
: bIsValid(true)
|
: bIsValid(true)
|
||||||
{
|
{
|
||||||
new(&Value) OptionalType(Forward<Types>(Args)...);
|
new(&Value) OptionalType(Forward<Types>(Args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T = OptionalType> requires TIsConstructible<OptionalType, T&&>::Value
|
template <typename T = OptionalType> requires TIsConstructible<OptionalType, T&&>::Value
|
||||||
&& (!TIsSame<typename TRemoveCVRef<T>::Type, EInPlace>::Value) && (!TIsSame<typename TRemoveCVRef<T>::Type, TOptional>::Value)
|
&& (!TIsSame<typename TRemoveCVRef<T>::Type, FInPlace>::Value) && (!TIsSame<typename TRemoveCVRef<T>::Type, TOptional>::Value)
|
||||||
constexpr explicit(!TIsConvertible<T&&, OptionalType>::Value) TOptional(T&& InValue)
|
constexpr explicit(!TIsConvertible<T&&, OptionalType>::Value) TOptional(T&& InValue)
|
||||||
: TOptional(InPlace, Forward<T>(InValue))
|
: TOptional(InPlace, Forward<T>(InValue))
|
||||||
{ }
|
{ }
|
||||||
@ -250,6 +251,12 @@ constexpr bool operator!=(const T& LHS, const TOptional<U>& RHS)
|
|||||||
return RHS.IsValid() ? LHS != *RHS : true;
|
return RHS.IsValid() ? LHS != *RHS : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr TOptional<typename TDecay<T>::Type> MakeOptional(FInvalid)
|
||||||
|
{
|
||||||
|
return TOptional<typename TDecay<T>::Type>(Invalid);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
constexpr TOptional<typename TDecay<T>::Type> MakeOptional(T&& InValue)
|
constexpr TOptional<typename TDecay<T>::Type> MakeOptional(T&& InValue)
|
||||||
{
|
{
|
||||||
|
29
Redcraft.Utility/Source/Public/Templates/Placeholders.h
Normal file
29
Redcraft.Utility/Source/Public/Templates/Placeholders.h
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreTypes.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{};
|
||||||
|
|
||||||
|
NAMESPACE_MODULE_END(Utility)
|
||||||
|
NAMESPACE_MODULE_END(Redcraft)
|
||||||
|
NAMESPACE_REDCRAFT_END
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Templates/Utility.h"
|
#include "Templates/Utility.h"
|
||||||
|
#include "Templates/Placeholders.h"
|
||||||
#include "Templates/Container.h"
|
#include "Templates/Container.h"
|
||||||
#include "Templates/Noncopyable.h"
|
#include "Templates/Noncopyable.h"
|
||||||
#include "Templates/Invoke.h"
|
#include "Templates/Invoke.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user