refactor(typetraits): replaces template class type traits with concepts for TypeTraits/SupportedOperations.h

This commit is contained in:
2022-05-16 22:42:17 +08:00
parent c316b8f190
commit 413762a90a
16 changed files with 213 additions and 261 deletions

View File

@ -65,7 +65,7 @@ private:
// Optimize TOptional with these hacking
constexpr TReferenceWrapper(FInvalid) : Pointer(nullptr) { };
template <typename T> requires TIsDestructible<T>::Value friend struct TOptional;
template <typename T> requires CDestructible<T> friend struct TOptional;
};
@ -116,18 +116,18 @@ private:
template <typename T>
struct TAllowUnwrapping : TBoolConstant<!(
TIsConstructible<OptionalType, TOptional<T>& >::Value
|| TIsConstructible<OptionalType, const TOptional<T>& >::Value
|| TIsConstructible<OptionalType, TOptional<T>&&>::Value
|| TIsConstructible<OptionalType, const TOptional<T>&&>::Value
CConstructible<OptionalType, TOptional<T>& >
|| CConstructible<OptionalType, const TOptional<T>& >
|| CConstructible<OptionalType, TOptional<T>&&>
|| CConstructible<OptionalType, const TOptional<T>&&>
|| TIsConvertible< TOptional<T>&, OptionalType>::Value
|| TIsConvertible<const TOptional<T>&, OptionalType>::Value
|| TIsConvertible< TOptional<T>&&, OptionalType>::Value
|| TIsConvertible<const TOptional<T>&&, OptionalType>::Value
|| TIsAssignable<OptionalType&, TOptional<T>& >::Value
|| TIsAssignable<OptionalType&, const TOptional<T>& >::Value
|| TIsAssignable<OptionalType&, TOptional<T>&&>::Value
|| TIsAssignable<OptionalType&, const TOptional<T>&&>::Value
|| CAssignable<OptionalType&, TOptional<T>& >
|| CAssignable<OptionalType&, const TOptional<T>& >
|| CAssignable<OptionalType&, TOptional<T>&&>
|| CAssignable<OptionalType&, const TOptional<T>&&>
)> { };
public:
@ -138,12 +138,12 @@ public:
constexpr TOptional(FInvalid) : TOptional() { }
template <typename... Types> requires TIsConstructible<OptionalType, Types...>::Value
template <typename... Types> requires CConstructible<OptionalType, Types...>
constexpr explicit TOptional(FInPlace, Types&&... Args)
: Reference(Forward<Types>(Args)...)
{ }
template <typename T = OptionalType> requires TIsConstructible<OptionalType, T&&>::Value
template <typename T = OptionalType> requires CConstructible<OptionalType, T&&>
&& (!TIsSame<typename TRemoveCVRef<T>::Type, FInPlace>::Value) && (!TIsSame<typename TRemoveCVRef<T>::Type, TOptional>::Value)
constexpr explicit (!TIsConvertible<T&&, OptionalType>::Value) TOptional(T&& InValue)
: TOptional(InPlace, Forward<T>(InValue))
@ -152,7 +152,7 @@ public:
TOptional(const TOptional& InValue) = default;
TOptional(TOptional&& InValue) = default;
template <typename T = OptionalType> requires TIsConstructible<OptionalType, const T&>::Value && TAllowUnwrapping<T>::Value
template <typename T = OptionalType> requires CConstructible<OptionalType, const T&> && TAllowUnwrapping<T>::Value
constexpr explicit (!TIsConvertible<const T&, OptionalType>::Value) TOptional(const TOptional<T>& InValue)
: Reference(InValue.Reference)
{ }
@ -162,21 +162,21 @@ public:
TOptional& operator=(const TOptional& InValue) = default;
TOptional& operator=(TOptional&& InValue) = default;
template <typename T = OptionalType> requires TIsConstructible<OptionalType, const T&>::Value && TIsAssignable<OptionalType&, const T&>::Value && TAllowUnwrapping<T>::Value
template <typename T = OptionalType> requires CConstructible<OptionalType, const T&> && CAssignable<OptionalType&, const T&> && TAllowUnwrapping<T>::Value
constexpr TOptional& operator=(const TOptional<T>& InValue)
{
Reference = InValue.Reference;
return *this;
}
template <typename T = OptionalType> requires TIsConstructible<OptionalType, T&&>::Value && TIsAssignable<OptionalType&, T&&>::Value
template <typename T = OptionalType> requires CConstructible<OptionalType, T&&> && CAssignable<OptionalType&, T&&>
constexpr TOptional& operator=(T&& InValue)
{
Reference = InValue;
return *this;
}
template <typename... ArgTypes> requires TIsConstructible<OptionalType, ArgTypes...>::Value
template <typename... ArgTypes> requires CConstructible<OptionalType, ArgTypes...>
constexpr OptionalType& Emplace(ArgTypes&&... Args)
{
Reference = TReferenceWrapper<ReferencedType>(Forward<ArgTypes>(Args)...);
@ -221,7 +221,7 @@ public:
private:
TReferenceWrapper<ReferencedType> Reference;
template <typename T> requires TIsDestructible<T>::Value friend struct TOptional;
template <typename T> requires CDestructible<T> friend struct TOptional;
};