Is there a case where pass-by-reference is more expensive than pass-by-value in C++? If so, what would that case be?
Prefer passing primitive types (int, char, float, ...) and POD structs that are cheap to copy (Point, complex) by value.
This will be more efficient than the indirection required when passing by reference.
See Boost's Call Traits.
The template class
call_traits<T>
encapsulates the "best" method to pass a parameter of some type T to or from a function, and consists of a collection of typedefs defined as in the table below. The purpose ofcall_traits
is to ensure that problems like "references to references" never occur, and that parameters are passed in the most efficient manner possible.
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