feat(templates): add TOptional and TVariant to compare the equivalence of Invalid

This commit is contained in:
_Redstone_c_ 2022-03-22 11:12:05 +08:00
parent be1d91591c
commit 2f55c84c32
2 changed files with 49 additions and 0 deletions

View File

@ -249,6 +249,30 @@ constexpr bool operator!=(const T& LHS, const TOptional<U>& RHS)
return RHS.IsValid() ? LHS != *RHS : true;
}
template <typename T>
constexpr bool operator==(const TOptional<T>& LHS, FInvalid)
{
return !LHS.IsValid();
}
template <typename T>
constexpr bool operator!=(const TOptional<T>& LHS, FInvalid)
{
return LHS.IsValid();
}
template <typename T>
constexpr bool operator==(FInvalid, const TOptional<T>& RHS)
{
return !RHS.IsValid();
}
template <typename T>
constexpr bool operator!=(FInvalid, const TOptional<T>& RHS)
{
return RHS.IsValid();
}
template <typename T>
constexpr TOptional<typename TDecay<T>::Type> MakeOptional(FInvalid)
{

View File

@ -4,6 +4,7 @@
#include "Templates/Invoke.h"
#include "Templates/Utility.h"
#include "TypeTraits/TypeTraits.h"
#include "Miscellaneous/AssertionMacros.h"
NAMESPACE_REDCRAFT_BEGIN
NAMESPACE_MODULE_BEGIN(Redcraft)
@ -474,6 +475,30 @@ constexpr bool operator!=(const T& LHS, const TVariant<Types...>& RHS)
return RHS.template HoldsAlternative<T>() ? LHS != RHS.template GetValue<T>() : true;
}
template <typename... Types>
constexpr bool operator==(const TVariant<Types...>& LHS, FInvalid)
{
return !LHS.IsValid();
}
template <typename... Types>
constexpr bool operator!=(const TVariant<Types...>& LHS, FInvalid)
{
return LHS.IsValid();
}
template <typename... Types>
constexpr bool operator==(FInvalid, const TVariant<Types...>& RHS)
{
return !RHS.IsValid();
}
template <typename... Types>
constexpr bool operator!=(FInvalid, const TVariant<Types...>& RHS)
{
return RHS.IsValid();
}
template <typename... Types> requires (true && ... && (TIsMoveConstructible<Types>::Value && TIsSwappable<Types>::Value))
constexpr void Swap(TVariant<Types...>& A, TVariant<Types...>& B)
{