perf(templates): add requires on the content of TOptional and TVariant

This commit is contained in:
_Redstone_c_ 2022-03-21 18:40:30 +08:00
parent e03cfa956c
commit e0aab7e0b9
2 changed files with 8 additions and 21 deletions

View File

@ -9,7 +9,7 @@ NAMESPACE_REDCRAFT_BEGIN
NAMESPACE_MODULE_BEGIN(Redcraft)
NAMESPACE_MODULE_BEGIN(Utility)
template <typename OptionalType>
template <typename OptionalType> requires (TIsObject<OptionalType>::Value && !TIsArray<OptionalType>::Value&& TIsDestructible<OptionalType>::Value)
struct TOptional
{
public:

View File

@ -85,7 +85,7 @@ template <typename T>
constexpr void VariantCopyConstruct(void* Target, const void* Source)
{
if constexpr (!TIsCopyConstructible<T>::Value || TIsConst<T>::Value) check_no_entry();
new(reinterpret_cast<T*>(Target)) T(*reinterpret_cast<const T*>(Source));
else new(reinterpret_cast<T*>(Target)) T(*reinterpret_cast<const T*>(Source));
}
using FVariantCopyConstructFunc = void(*)(void*, const void*);
@ -94,7 +94,7 @@ template <typename T>
constexpr void VariantMoveConstruct(void* Target, void* Source)
{
if constexpr (!TIsMoveConstructible<T>::Value || TIsConst<T>::Value) check_no_entry();
new(reinterpret_cast<T*>(Target)) T(MoveTemp(*reinterpret_cast<T*>(Source)));
else new(reinterpret_cast<T*>(Target)) T(MoveTemp(*reinterpret_cast<T*>(Source)));
}
using FVariantMoveConstructFunc = void(*)(void*, void*);
@ -103,7 +103,7 @@ template <typename T>
constexpr void VariantCopyAssign(void* Target, const void* Source)
{
if constexpr (!TIsCopyAssignable<T>::Value || TIsConst<T>::Value) check_no_entry();
*reinterpret_cast<T*>(Target) = *reinterpret_cast<const T*>(Source);
else *reinterpret_cast<T*>(Target) = *reinterpret_cast<const T*>(Source);
}
using FVariantCopyAssignFunc = void(*)(void*, const void*);
@ -112,7 +112,7 @@ template <typename T>
constexpr void VariantMoveAssign(void* Target, void* Source)
{
if constexpr (!TIsMoveAssignable<T>::Value || TIsConst<T>::Value) check_no_entry();
*reinterpret_cast<T*>(Target) = MoveTemp(*reinterpret_cast<T*>(Source));
else *reinterpret_cast<T*>(Target) = MoveTemp(*reinterpret_cast<T*>(Source));
}
using FVariantMoveAssignFunc = void(*)(void*, void*);
@ -149,14 +149,6 @@ struct TVariantHelper
static constexpr FVariantInequalityOperatorFunc InequalityOperatorFuncs[] = { VariantInequalityOperator<Types>... };
};
template <typename... Types> constexpr FVariantDestroyFunc TVariantHelper<Types...>::DestroyFuncs[];
template <typename... Types> constexpr FVariantCopyConstructFunc TVariantHelper<Types...>::CopyConstructFuncs[];
template <typename... Types> constexpr FVariantMoveConstructFunc TVariantHelper<Types...>::MoveConstructFuncs[];
template <typename... Types> constexpr FVariantCopyAssignFunc TVariantHelper<Types...>::CopyAssignFuncs[];
template <typename... Types> constexpr FVariantMoveAssignFunc TVariantHelper<Types...>::MoveAssignFuncs[];
template <typename... Types> constexpr FVariantEqualityOperatorFunc TVariantHelper<Types...>::EqualityOperatorFuncs[];
template <typename... Types> constexpr FVariantInequalityOperatorFunc TVariantHelper<Types...>::InequalityOperatorFuncs[];
template <typename R, typename F, typename T>
constexpr R VariantVisitLValue(F&& Func, void* Arg)
{
@ -210,14 +202,9 @@ struct TVariantVisitHelper
static constexpr FVariantVisitConstRValueFunc<R, F> VisitConstRValueFuncs[] = { VariantVisitConstRValue<R, F, Types>... };
};
template <typename R, typename F, typename... Types> constexpr FVariantVisitLValueFunc<R, F> TVariantVisitHelper<R, F, Types...>::VisitLValueFuncs[];
template <typename R, typename F, typename... Types> constexpr FVariantVisitRValueFunc<R, F> TVariantVisitHelper<R, F, Types...>::VisitRValueFuncs[];
template <typename R, typename F, typename... Types> constexpr FVariantVisitConstLValueFunc<R, F> TVariantVisitHelper<R, F, Types...>::VisitConstLValueFuncs[];
template <typename R, typename F, typename... Types> constexpr FVariantVisitConstRValueFunc<R, F> TVariantVisitHelper<R, F, Types...>::VisitConstRValueFuncs[];
NAMESPACE_PRIVATE_END
template <typename... Types>
template <typename... Types> requires (true && ... && (TIsObject<Types>::Value && !TIsArray<Types>::Value && TIsDestructible<Types>::Value))
struct TVariant
{
struct FAlternativeSize : TConstant<size_t, sizeof...(Types)> { };