feat(templates): add type traits to determine if it is TAny etc
This commit is contained in:
parent
54ab72224f
commit
5f4b0d8c22
@ -119,12 +119,12 @@ struct TAnyRTTIHelper
|
||||
};
|
||||
};
|
||||
|
||||
inline constexpr size_t ANY_DEFAULT_INLINE_SIZE = 64 - sizeof(FTypeInfo) - sizeof(const FAnyRTTI*);
|
||||
inline constexpr size_t ANY_DEFAULT_INLINE_ALIGNMENT = Memory::MINIMUM_ALIGNMENT;
|
||||
|
||||
NAMESPACE_PRIVATE_END
|
||||
|
||||
template <size_t InlineSize, size_t InlineAlignment = NAMESPACE_PRIVATE::ANY_DEFAULT_INLINE_ALIGNMENT>
|
||||
inline constexpr size_t ANY_DEFAULT_INLINE_SIZE = 64 - sizeof(FTypeInfo) - sizeof(const NAMESPACE_PRIVATE::FAnyRTTI*);
|
||||
inline constexpr size_t ANY_DEFAULT_INLINE_ALIGNMENT = Memory::MINIMUM_ALIGNMENT;
|
||||
|
||||
template <size_t InlineSize, size_t InlineAlignment = ANY_DEFAULT_INLINE_ALIGNMENT>
|
||||
struct TAny
|
||||
{
|
||||
template <typename T>
|
||||
@ -186,7 +186,7 @@ struct TAny
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> requires (!TIsSame<typename TDecay<T>::Type, TAny>::Value) && (!TIsInPlaceTypeSpecialization<typename TDecay<T>::Type>::Value)
|
||||
template <typename T> requires (!TIsSame<typename TDecay<T>::Type, TAny>::Value) && (!TIsTInPlaceType<typename TDecay<T>::Type>::Value)
|
||||
&& TIsObject<typename TDecay<T>::Type>::Value && (!TIsArray<typename TDecay<T>::Type>::Value) && TIsDestructible<typename TDecay<T>::Type>::Value
|
||||
&& TIsConstructible<typename TDecay<T>::Type, T&&>::Value
|
||||
TAny(T&& InValue) : TAny(InPlaceType<typename TDecay<T>::Type>, Forward<T>(InValue))
|
||||
@ -255,7 +255,7 @@ struct TAny
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T> requires (!TIsSame<typename TDecay<T>::Type, TAny>::Value) && (!TIsInPlaceTypeSpecialization<typename TDecay<T>::Type>::Value)
|
||||
template <typename T> requires (!TIsSame<typename TDecay<T>::Type, TAny>::Value) && (!TIsTInPlaceType<typename TDecay<T>::Type>::Value)
|
||||
&& TIsObject<typename TDecay<T>::Type>::Value && (!TIsArray<typename TDecay<T>::Type>::Value) && TIsDestructible<typename TDecay<T>::Type>::Value
|
||||
&& TIsConstructible<typename TDecay<T>::Type, T&&>::Value
|
||||
TAny& operator=(T&& InValue)
|
||||
@ -451,7 +451,10 @@ constexpr void Swap(TAny<InlineSize, InlineAlignment>& A, TAny<InlineSize, Inlin
|
||||
B = MoveTemp(Temp);
|
||||
}
|
||||
|
||||
using FAny = TAny<NAMESPACE_PRIVATE::ANY_DEFAULT_INLINE_SIZE>;
|
||||
template <typename T> struct TIsTAny : FFalse { };
|
||||
template <size_t InlineSize, size_t InlineAlignment> struct TIsTAny<TAny<InlineSize, InlineAlignment>> : FTrue { };
|
||||
|
||||
using FAny = TAny<ANY_DEFAULT_INLINE_SIZE>;
|
||||
|
||||
static_assert(sizeof(FAny) == 64, "The byte size of FAny is unexpected");
|
||||
|
||||
|
@ -321,6 +321,9 @@ constexpr void Swap(TOptional<T>& A, TOptional<T>& B)
|
||||
Swap(*A, *B);
|
||||
}
|
||||
|
||||
template <typename T> struct TIsTOptional : FFalse { };
|
||||
template <typename T> struct TIsTOptional<TOptional<T>> : FTrue { };
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
NAMESPACE_REDCRAFT_END
|
||||
|
@ -40,6 +40,9 @@ private:
|
||||
template <typename T>
|
||||
TReferenceWrapper(T&) -> TReferenceWrapper<T>;
|
||||
|
||||
template <typename T> struct TIsTReferenceWrapper : FFalse { };
|
||||
template <typename T> struct TIsTReferenceWrapper<TReferenceWrapper<T>> : FTrue { };
|
||||
|
||||
template <typename T> struct TUnwrapReference { using Type = T; };
|
||||
template <typename T> struct TUnwrapReference<TReferenceWrapper<T>> { using Type = T&; };
|
||||
|
||||
|
@ -379,16 +379,16 @@ TTuple(Types...) -> TTuple<Types...>;
|
||||
template <typename T, typename U>
|
||||
using TPair = TTuple<T, U>;
|
||||
|
||||
template <typename T > struct TIsTupleSpecialization : FFalse { };
|
||||
template <typename... Types> struct TIsTupleSpecialization<TTuple<Types...>> : FTrue { };
|
||||
template <typename T > struct TIsTTuple : FFalse { };
|
||||
template <typename... Types> struct TIsTTuple<TTuple<Types...>> : FTrue { };
|
||||
|
||||
template <typename TupleType> requires TIsTupleSpecialization<typename TRemoveCVRef<TupleType>::Type>::Value
|
||||
template <typename TupleType> requires TIsTTuple<typename TRemoveCVRef<TupleType>::Type>::Value
|
||||
struct TTupleElementSize : TConstant<size_t, TRemoveCVRef<TupleType>::Type::ElementSize> { };
|
||||
|
||||
template <size_t I, typename TupleType> requires TIsTupleSpecialization<typename TRemoveCVRef<TupleType>::Type>::Value
|
||||
template <size_t I, typename TupleType> requires TIsTTuple<typename TRemoveCVRef<TupleType>::Type>::Value
|
||||
struct TTupleElementType { using Type = typename TCopyCVRef<typename TRemoveReference<TupleType>::Type, typename TRemoveCVRef<TupleType>::Type::template TElementType<I>::Type>::Type; };
|
||||
|
||||
template <typename T, typename TupleType> requires TIsTupleSpecialization<typename TRemoveCVRef<TupleType>::Type>::Value
|
||||
template <typename T, typename TupleType> requires TIsTTuple<typename TRemoveCVRef<TupleType>::Type>::Value
|
||||
struct TTupleElementIndex : TupleType::template TElementIndex<T> { };
|
||||
|
||||
template <typename... Types>
|
||||
@ -553,10 +553,10 @@ struct TTupleVisitImpl<TIndexSequence<>>
|
||||
|
||||
NAMESPACE_PRIVATE_END
|
||||
|
||||
template <typename... TTupleTypes> requires (true && ... && (TIsTupleSpecialization<typename TRemoveCVRef<TTupleTypes>::Type>::Value))
|
||||
template <typename... TTupleTypes> requires (true && ... && (TIsTTuple<typename TRemoveCVRef<TTupleTypes>::Type>::Value))
|
||||
struct TTupleCatResult { using Type = typename NAMESPACE_PRIVATE::TTupleCatResultImpl<typename TRemoveReference<TTupleTypes>::Type..., NAMESPACE_PRIVATE::FTupleEndFlag>::Type; };
|
||||
|
||||
template <typename... TTupleTypes> requires (true && ... && (TIsTupleSpecialization<typename TRemoveCVRef<TTupleTypes>::Type>::Value))
|
||||
template <typename... TTupleTypes> requires (true && ... && (TIsTTuple<typename TRemoveCVRef<TTupleTypes>::Type>::Value))
|
||||
constexpr auto TupleCat(TTupleTypes&&... Args)
|
||||
{
|
||||
using R = typename TTupleCatResult<TTupleTypes...>::Type;
|
||||
|
@ -245,7 +245,7 @@ struct TVariant
|
||||
{ }
|
||||
|
||||
template <typename T> requires NAMESPACE_PRIVATE::TVariantSelectedType<typename TRemoveReference<T>::Type, Types...>::Value
|
||||
&& (!TIsInPlaceTypeSpecialization<typename TRemoveCVRef<T>::Type>::Value) && (!TIsInPlaceIndexSpecialization<typename TRemoveCVRef<T>::Type>::Value)
|
||||
&& (!TIsTInPlaceType<typename TRemoveCVRef<T>::Type>::Value) && (!TIsTInPlaceIndex<typename TRemoveCVRef<T>::Type>::Value)
|
||||
&& (!TIsSame<typename TRemoveCVRef<T>::Type, TVariant>::Value)
|
||||
constexpr TVariant(T&& InValue) : TVariant(InPlaceType<typename NAMESPACE_PRIVATE::TVariantSelectedType<typename TRemoveReference<T>::Type, Types...>::Type>, Forward<T>(InValue))
|
||||
{ }
|
||||
@ -532,16 +532,16 @@ constexpr void Swap(TVariant<Types...>& A, TVariant<Types...>& B)
|
||||
B = MoveTemp(Temp);
|
||||
}
|
||||
|
||||
template <typename T > struct TIsVariantSpecialization : FFalse { };
|
||||
template <typename... Types> struct TIsVariantSpecialization<TVariant<Types...>> : FTrue { };
|
||||
template <typename T > struct TIsTVariant : FFalse { };
|
||||
template <typename... Types> struct TIsTVariant<TVariant<Types...>> : FTrue { };
|
||||
|
||||
template <typename VariantType> requires TIsVariantSpecialization<typename TRemoveCVRef<VariantType>::Type>::Value
|
||||
template <typename VariantType> requires TIsTVariant<typename TRemoveCVRef<VariantType>::Type>::Value
|
||||
struct TVariantAlternativeSize : TConstant<size_t, VariantType::AlternativeSize> { };
|
||||
|
||||
template <size_t I, typename VariantType> requires TIsVariantSpecialization<typename TRemoveCVRef<VariantType>::Type>::Value
|
||||
template <size_t I, typename VariantType> requires TIsTVariant<typename TRemoveCVRef<VariantType>::Type>::Value
|
||||
struct TVariantAlternativeType { using Type = typename TCopyCV<typename TRemoveReference<VariantType>::Type, typename TRemoveCVRef<VariantType>::Type::template TAlternativeType<I>::Type>::Type; };
|
||||
|
||||
template <typename T, typename VariantType> requires TIsVariantSpecialization<typename TRemoveCVRef<VariantType>::Type>::Value
|
||||
template <typename T, typename VariantType> requires TIsTVariant<typename TRemoveCVRef<VariantType>::Type>::Value
|
||||
struct TVariantAlternativeIndex : VariantType::template TAlternativeIndex<T> { };
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
|
@ -7,11 +7,11 @@ 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 TIsTInPlaceType : FFalse { };
|
||||
template <typename T> struct TIsTInPlaceType<TInPlaceType<T>> : FTrue { };
|
||||
|
||||
template <typename T> struct TIsInPlaceIndexSpecialization : FFalse { };
|
||||
template <size_t I> struct TIsInPlaceIndexSpecialization<TInPlaceIndex<I>> : FTrue { };
|
||||
template <typename T> struct TIsTInPlaceIndex : FFalse { };
|
||||
template <size_t I> struct TIsTInPlaceIndex<TInPlaceIndex<I>> : FTrue { };
|
||||
|
||||
NAMESPACE_MODULE_END(Utility)
|
||||
NAMESPACE_MODULE_END(Redcraft)
|
||||
|
Loading…
Reference in New Issue
Block a user