Sure:
template<typename T, bool=true> struct eff_arg { typedef T type; }; template<typename T> struct eff_arg<T, (sizeof(T)>sizeof(int))> { typedef T const& type; };
using:
template <class T> class tmplClass {
and replace sizeof(int) with whatever type you want to use as "the point at which you want to pass the link, not by value."
Note that parameter size is a mediocre way to make this decision: an extremely small class (even smaller than a pointer!) Can have deep copy semantics when a large structure is duplicated when it is duplicated. And often, circumcision does not have to be an int size or a pointer, but more, because indirection has value.
The idea may be to copy only objects that do not manage resources and are small enough. std::is_trivially_copyable<T>::value && (sizeof(T) <= 2*sizeof(void*)) may be the type of check you must do before passing T , not T const& , when you don't need a copy of the data .
This leads to the following:
template<typename T, bool=true> struct eff_arg { typedef T const& type; }; template<typename T> struct eff_arg<T, std::is_trivially_copyable<T>::value && (sizeof(T)<=2*sizeof(void*)) > { typedef T type; }; template<typename T> using EffArg = typename eff_arg<T>::type;
Yakk source share