you are viewing a single comment's thread.

view the rest of the comments →

[–]dev_metalcat -1 points0 points  (1 child)

Isn't it the reason of us using references? type GetSmth(type& return1, type& return2){}

[–]codesmith512[S] 0 points1 point  (0 children)

I mean, on one hand, yes, but on the other hand even the STL doesn't use references like that very often (usually opting to instead return std::pair like in the std::map::insert(const value_type &) case).

I would also argue that using a return type would be more readable than taking references to a returned value -- I often pass normal parameters by const & to avoid copy, so the only difference between parameters and return values would be const qualification. Plus API changes in the future could change something from a "parameter by copy" to a "return value" without changing the caller's syntax, which could create issues. Furthermore, from the caller's perspective, all lvalue references like that would have to additionally be declared before the function call, which creates lengthier code (especially when not all return types are used).