I've always heard that a good practice to ensure best performance was to:
- pass fundamental types (
int
,double
...) by value - pass classes by const reference
Nowadays, using C++11 and full optimizations under a compiler, is there an overhead when one passes a fundamental type by const reference?
And furthermore, when T
is int
will the following function:
template <typename T> inline void f(const T& x);
be slower than:
template <typename T> inline void f(const T x);