Returns a vector slower than passing by reference?

In the old days, we were trained to use result parameters passed by reference to avoid unnecessary data copying.

However, with smarter compilers and specific extensions for C ++ 11, is this still required ?

In particular, is there any reason in 2018 with modern C ++ 11 / C ++ 14 compilers (still) to use

void Filter(vector<CObject*> &elements, vector<CObject*> &outElements);

instead of simply returning a vector, i.e.

vector<CObject*> Filter(vector<CObject*> &elements);

Thank you in advance for your understanding!

+6
source share
3 answers

and in particular extensions for C ++ 11, is this still required?

. RVO ( ) , /.

. std::vector ( ).

, Filter(some_input) rvalue std::vector<CObject*>, std::vector , rvalue: . (6) .

+10

, , .

, - ++, : , - .

, const ( ).

, , , . RVO NRVO ( ) , , .

+2

, , . , . .

0
source

All Articles