mercredi 28 septembre 2016

Why can't I use make_pair to tie?

I'm trying to mimic the behavior of tie pre C++11.

pair<int, int> test() {
    return make_pair(13, 42);
}

int main() {
    int a = 1, b = 2;

    pair<int&, int&>(a, b) = test();

    cout << a << ' ' << b << endl;
}

This works however if I use make_pair instead to the pair constructor a and b are not assigned.
Why does the pair constructor work but not make_pair?

Aucun commentaire:

Enregistrer un commentaire