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; }
?
@namark
add2 makes chaining expensive?
@hanken it does? I though it makes it cheaper... sans a rookie mistake on my part, see this thread
https://qoto.org/web/statuses/106839448913933165
@hanken move not guaranteed as in T might not have a move constructor? Preposterous! I'm not changing my functions you fix your types :<
Anyhow, I posted my answer
https://qoto.org/web/statuses/106862742673984441
@hanken no one ever expects arithmetic type promotion! This is why you can't in general implement/de-duplicate/replace operator+ with operator+=, and it's even bigger deal when you take into account types that use expression templates, or have bounds or measurement units associated with them at compile time.
@namark
Wow. This is good!
After looking at your answer I thought, sure, the return types might not be same. But I checked it and wow. add1 is not returning T! Only add2 does.
Thanks for sharing this.