mercredi 26 juin 2019

Undefined behaviour in initializer list order using move semantics

Is (1) undefined behavior, or is the first element of the pair always evaluated first?

#include <array>
#include <utility>

int bar(std::array<int, 3>&& ) {
    return 1;
}

std::pair<std::array<int, 3>, int> foo() {
    std::array<int, 3> a;
    return { a, bar(std::move(a)) };  // (1)
}

As a side note, would using return make_pair(a, bar(std::move(a))); instead be different?

Aucun commentaire:

Enregistrer un commentaire