Is there a case where pass-by-reference is more expensive than pass-by-value in C++? If so, what would that case be?
See Question&Answers more detail:osIs there a case where pass-by-reference is more expensive than pass-by-value in C++? If so, what would that case be?
See Question&Answers more detail:osPrefer 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.