Relative Content

Tag Archive for c++c++17copy-elisionnrvo

C++ NRVO in the presence of multiple return points

I have the following C++ code that returns a std::tuple<std::vector<int>, std::vector<int>>. My question is about copy elision and named return value optimisation. As I understand, since C++-17, the standard mandates that the return value will be copy-elided. So no temporary tuple will be created and then, (I assume) std::tie will directly initialise list1, list2. Now, whether it will call a copy or move constructor for the vectors or allocate space before function call and directly use that space depends on whether NRVO is performed. I would like to know whether NRVO is performed in this case, and if not, how I can change the code to achieve a single vector allocation for both lists (without passing them in as parameters).