Say I have two templates for an operator=
overloading :
class MyClass {
public:
template <typename T>
std::enable_if_t<true == /* a condition */, MyClass&>
operator=(T value) {
std::cout << "Pass by copy" << std::endl;
}
template <typename T>
std::enable_if_t<false == /* a condition */, MyClass&>
operator=(const T &value) {
std::cout << "Pass by reference" << std::endl;
}
};
What would be the most optimal condition to use with std::enable_if
?
I came up with this :
template <typename T>
struct pass_copy_cond : std::conditional<
std::is_fundamental<T>::value ||
std::is_pointer<T>::value ||
(std::is_trivial<T>::value && sizeof(T) < sizeof(void*))
, std::true_type, std::false_type>::type {};
Is there a way to improve the condition ?