what's the difference between
template<typename T>
auto add1(const T& a, const T& b)
{ return a + b; }
and
template<typename T>
auto add2(T a, const T& b)
{ return a += b; }
?
@pleb I gave the counter a try, and seems like I need {a+=b; return a;} for the optimizations to kick in, then for both cases there's a single copy in your example. If you pass a temporary as a first parameter though, you'll get a move instead of a copy with add2, and for that reason it's a general rule of thumb in modern c++: if you know you need a copy - pass by value. That said there is a bigger semantic difference there that I had in mind.