mardi 28 février 2017

Does C++11 guarantee a dying object will be moved rather than copied as an argument?

#include <vector>

using namespace std;

void f(const vector<int>&) {}
void f(vector<int>&&) {}

int main()
{
    while (true)
    {
        vector<int> coll;

        //
        // coll is dying, so,
        // "f(coll)" will call "f(const vector<int>&)" or
        // "f(vector<int>&&)" as per C++11?
        //
        f(coll); 
    }
}

In the code above, coll is dying; so, f(coll) will call f(const vector<int>&) or f(vector<int>&&) as per C++11?

Aucun commentaire:

Enregistrer un commentaire