Is there a need performance-wise for inline functions to pass its arguments by const reference like
foo(const T & a, const T &b)
compared to by value
foo(T a, T b)
if I don't change the values of a and b in the function? Does C++11 change recommend anything specific here?
Pass by value can only elide the copy-constructor call if the argument is a temporary.
Passing primitive types by const reference will have no cost when the function is inlined. But passing a complex lvalue by value will impose a potentially expensive copy constructor call. So prefer to pass by const reference (if aliasing is not a problem).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With