samedi 16 janvier 2021

std::make_pair deduces template argument as rvalue reference

I'm not getting why my compiler is deducing the std::make_pair template arguments as rvalue reference(&&). Can somebody explain why the below code doesn't compile

    int main() {
        std::vector<int> process_ID_list { 1345, 45, 5646, 52525, 55757, 23424, 68696, 55878, 667, 252 };
        std::vector<int> process_pri_list { 41, 334, 747, 41, 47, 7, 75, 544, 42, 6 };
        std::vector<std::pair<int, int>> pair_list;
        for (int i = 0; i < process_ID_list.size(); ++i) {
            int pro_ID = process_ID_list.at(i);
            int pro_pri = process_pri_list.at(i);

            // pair_list.emplace_back(std::make_pair(pro_ID, pro_pri)); // this compiles
            pair_list.emplace_back(std::make_pair<int, int>(pro_ID, pro_pri)); //this doesn't compile telling cannot bind rvalue reference of type ‘int&&’ to lvalue
        }

    return (EXIT_SUCCESS);
}

Aucun commentaire:

Enregistrer un commentaire