ScopedPointer semantics, STL

what’s so bad about “const int&” parameters?

I’d say you don’t gain anything in the size of the parameter cause the reference to int is the same size as int (or even greater on x64). Also the compiler won’t use processor registers for the parameter.


A reference is a pointer in reality, and when you pass a “const int &”, you must dereference the pointer to access the value, while you don’t need to do so with “const int”.
Also, one can use const_cast on the parameter to remove the “constness”, and modify your calling code, which is not allowed (obviously) with “const int” (I’ve seen a memory corruption in a code I had to debug once, because a “senior developer” thought that changing the “const int & size” parameter of an array passed in would magically reduce its size to what he wanted).

This can sound futile, but it make you win on each function call, and is more robust to stupid error.

I originally wrote PARAMETER_TYPE to handle some complicated type-fiddling in the ListenerList, where for some very obscure reason that I can’t remember, it was impossible to just say “const Type&”, and needed something that behaved appropriately for different types. But it’s handy in cases like this too.

So what are your thoughts on this:

template <class Mf, typename T1> void call (Mf mf, const T1& t1) { queue_fn (bind (mf, _1, t1)); }

Would I be benefiting from PARAMETER_TYPE here?

Hmm, it’d probably be hard for the compiler to deal with that - it’s probably best used on types that are defined as a class template parameter rather than a function template where it needs to infer the type you mean from the context.