dimanche 26 février 2017

What's the difference between "auto v = f()" and "auto&& v = f()"?

#include <vector>

using namespace std;

vector<int> f()
{
    return{};
}

void g(vector<int>)
{}

void g(vector<int>&&)
{}

int main()
{
    auto   v1 = f();
    auto&& v2 = f();

    g(forward<vector<int>>(v1));
    g(forward<vector<int>>(v2));
}

Does C++11 guarantee g(forward<vector<int>>(v1)) will call f(vector<int>) and g(forward<vector<int>>(v2)) will call f(vector<int>&&)?

Aucun commentaire:

Enregistrer un commentaire