The boost::call_traits
header deals with exactly this issue. Check it out here.
Specifically, the call_traits<T>::param_type
option includes the following description:
If
T
is a small built in type or a pointer, thenparam_type
is defined asT const
, instead ofT const&
. This can improve the ability of the compiler to optimize loops in the body of the function if they depend upon the passed parameter, the semantics of the passed parameter is otherwise unchanged (requires partial specialization).
In your case, you could define ingest
as follows:
template <class T>
class HungryHippo {
public:
void ingest(call_traits<T>::param_type object);
// "object" will be passed-by-value for small
// built-in types, but passed as a const reference
// otherwise
private:
...
};
Whether this would actually make much of a difference in your actual code/compiler combination, I'm not sure. As always, you'd have to run some actual benchmarks and see what happens...