vendredi 24 février 2017

Does C++11 guarantee the local variable in the return statement will be moved rather than copied?

#include <vector>

using namespace std;

struct A
{
    A(const vector<int>&) {}
    A(vector<int>&&) {}
};

A f()
{
    vector<int> coll;
    return A{ coll }; // Which constructor of A will be called as per C++11?
}

int main()
{
    f();
}

Does C++11 guarantee A(vector<int>&&) will be called on f returns?

In other words:

Does C++11 guarantee the local variable in the return statement will be moved rather than copied?

Aucun commentaire:

Enregistrer un commentaire