If I have a little peice o’ code as such…
template <typename _T>
class Foo
{
public:
typedef const T& ParamType;
void DoStuff(ParamType thingy);
};
This can be non-optimal if sizeof(_T) <= sizeof(_T*).
Therefore, I want to have a conditional typedef. If the size of _T is less than or equal to that of a pointer, just pass it in by value. Otherwise, pass it by const reference. Is this possible? I hear all this stuff about templates being turing complete but this is hurting my head.
Quite easy to achieve using partial template specialization.
EDIT As per Jeff’s sol’n one should indeed compare
sizeof(_T)andsizeof(_T&)but I kept the original<= void*requirement.