refactor(templates): remove the predefined functors, Lambda is a better choice

This commit is contained in:
2022-04-24 22:54:08 +08:00
parent c2eca8df1e
commit f72d6a53d8
2 changed files with 1 additions and 229 deletions

View File

@ -403,29 +403,6 @@ constexpr bool operator==(const TUniqueFunction<F>& LHS, nullptr_t)
static_assert(sizeof(TFunction<void()>) == 64, "The byte size of TFunction is unexpected");
static_assert(sizeof(TUniqueFunction<void()>) == 64, "The byte size of TUniqueFunction is unexpected");
template <typename T = void>
struct TIdentity
{
using Type = T;
constexpr T&& operator()(T&& InValue) const
{
return Forward<T>(InValue);
}
};
template <>
struct TIdentity<void>
{
using Type = void;
template<typename T>
constexpr T&& operator()(T&& InValue) const
{
return Forward<T>(InValue);
}
};
NAMESPACE_PRIVATE_BEGIN
template <typename F>
@ -476,136 +453,6 @@ constexpr NAMESPACE_PRIVATE::NotFunctionType<typename TDecay<F>::Type> NotFn(F&&
return NAMESPACE_PRIVATE::NotFunctionType<typename TDecay<F>::Type>(Forward<F>(Func));
}
#define FUNCTOR_UNARY_OPERATOR_IMPL(Name, Operator, ConceptT, ConceptU) \
template <typename T = void> requires (CSameAs<T, void> || ConceptT) \
struct Name \
{ \
constexpr auto operator()(const T& InValue) const \
-> decltype(Operator InValue) \
{ \
return Operator InValue; \
} \
}; \
\
template <> \
struct Name<void> \
{ \
template <typename U> requires ConceptU \
constexpr auto operator()(U&& InValue) const \
-> decltype(Operator Forward<U>(InValue)) \
{ \
return Operator Forward<U>(InValue); \
} \
}
#define FUNCTOR_BINARY_OPERATOR_IMPL(Name, Operator, ConceptT, ConceptTU) \
template <typename T = void> requires (CSameAs<T, void> || ConceptT) \
struct Name \
{ \
constexpr auto operator()(const T& LHS, const T& RHS) const \
-> decltype(LHS Operator RHS) \
{ \
return LHS Operator RHS; \
} \
}; \
\
template <> \
struct Name<void> \
{ \
template <typename T, typename U> requires ConceptTU \
constexpr auto operator()(T&& LHS, U&& RHS) const \
-> decltype(Forward<T>(LHS) Operator Forward<U>(RHS)) \
{ \
return Forward<T>(LHS) Operator Forward<U>(RHS); \
} \
}
#define FUNCTOR_UNARY_OPERATOR_A_IMPL(Name, Operator) \
FUNCTOR_UNARY_OPERATOR_IMPL \
( \
Name, Operator, \
(requires(const T& InValue) { { Operator InValue } -> CConvertibleTo<T>; }), \
(requires(U&& InValue) { Operator Forward<U>(InValue); }) \
)
#define FUNCTOR_BINARY_OPERATOR_A_IMPL(Name, Operator) \
FUNCTOR_BINARY_OPERATOR_IMPL \
( \
Name, Operator, \
(requires(const T& LHS, const T& RHS) { { LHS Operator RHS } -> CConvertibleTo<T>; }), \
(requires(T&& LHS, U&& RHS) { Forward<T>(LHS) Operator Forward<U>(RHS); }) \
)
#define FUNCTOR_UNARY_OPERATOR_B_IMPL(Name, Operator) \
FUNCTOR_UNARY_OPERATOR_IMPL \
( \
Name, Operator, \
(requires(const T& InValue) { { Operator InValue } -> CBooleanTestable; }), \
(requires(U&& InValue) { { Operator Forward<U>(InValue) } -> CBooleanTestable; }) \
)
#define FUNCTOR_BINARY_OPERATOR_B_IMPL(Name, Operator) \
FUNCTOR_BINARY_OPERATOR_IMPL \
( \
Name, Operator, \
(requires(const T& LHS, const T& RHS) { { LHS Operator RHS } -> CBooleanTestable; }), \
(requires(T&& LHS, U&& RHS) { { Forward<T>(LHS) Operator Forward<U>(RHS) } -> CBooleanTestable; }) \
)
#define FUNCTOR_BINARY_OPERATOR_C_IMPL(Name, Operator) \
FUNCTOR_BINARY_OPERATOR_IMPL \
( \
Name, Operator, \
(CEqualityComparable<T>), \
(CEqualityComparableWith<T, U>) \
)
#define FUNCTOR_BINARY_OPERATOR_D_IMPL(Name, Operator) \
FUNCTOR_BINARY_OPERATOR_IMPL \
( \
Name, Operator, \
(CTotallyOrdered<T>), \
(CTotallyOrderedWith<T, U>) \
)
FUNCTOR_UNARY_OPERATOR_A_IMPL (TPromote, +);
FUNCTOR_UNARY_OPERATOR_A_IMPL (TNegate, -);
FUNCTOR_BINARY_OPERATOR_A_IMPL(TPlus, +);
FUNCTOR_BINARY_OPERATOR_A_IMPL(TMinus, -);
FUNCTOR_BINARY_OPERATOR_A_IMPL(TMultiplies, *);
FUNCTOR_BINARY_OPERATOR_A_IMPL(TDivides, /);
FUNCTOR_BINARY_OPERATOR_A_IMPL(TModulus, %);
FUNCTOR_UNARY_OPERATOR_A_IMPL (TBitNot, ~ );
FUNCTOR_BINARY_OPERATOR_A_IMPL(TBitAnd, & );
FUNCTOR_BINARY_OPERATOR_A_IMPL(TBitOr, | );
FUNCTOR_BINARY_OPERATOR_A_IMPL(TBitXor, ^ );
FUNCTOR_BINARY_OPERATOR_A_IMPL(TBitLsh, <<);
FUNCTOR_BINARY_OPERATOR_A_IMPL(TBitRsh, >>);
FUNCTOR_BINARY_OPERATOR_B_IMPL(TLogicalAnd, &&);
FUNCTOR_BINARY_OPERATOR_B_IMPL(TLogicalOr, ||);
FUNCTOR_UNARY_OPERATOR_B_IMPL (TLogicalNot, ! );
FUNCTOR_BINARY_OPERATOR_C_IMPL(TEqualTo, ==);
FUNCTOR_BINARY_OPERATOR_C_IMPL(TNotEqualTo, !=);
FUNCTOR_BINARY_OPERATOR_D_IMPL(TGreater, > );
FUNCTOR_BINARY_OPERATOR_D_IMPL(TLess, < );
FUNCTOR_BINARY_OPERATOR_D_IMPL(TGreaterEqual, >=);
FUNCTOR_BINARY_OPERATOR_D_IMPL(TLessEqual, <=);
#undef FUNCTOR_BINARY_OPERATOR_D_IMPL
#undef FUNCTOR_BINARY_OPERATOR_C_IMPL
#undef FUNCTOR_BINARY_OPERATOR_B_IMPL
#undef FUNCTOR_UNARY_OPERATOR_B_IMPL
#undef FUNCTOR_BINARY_OPERATOR_A_IMPL
#undef FUNCTOR_UNARY_OPERATOR_A_IMPL
#undef FUNCTOR_BINARY_OPERATOR_IMPL
#undef FUNCTOR_UNARY_OPERATOR_IMPL
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)
NAMESPACE_REDCRAFT_END