mercredi 31 juillet 2019

template argument deduction/substitution failed erro, when iterating two maps simultaneously

I am trying to iterate two unordered maps simultaneously using a pair of two iterators. This method works fine if we iterate over two vectors;

#include <iostream>
#include<unordered_map>
using namespace std;

int main() 
{ 
    std::unordered_map<std::string,double> mypantry = flour;
    std::unordered_map<std::string, int> dubVec = key;
    std::unordered_map<std::string, std::string> intVec = {"key", "name"};
    double result = 0;

    typedef std::unordered_map<std::string, std::string>::iterator intIter;
    typedef std::unordered_map<std::string, bool>::iterator dubIter;

    for (std::pair<intIter, dubIter> i(intVec.begin(), dubVec.begin());
     i.first != intVec.end() && i.second != dubVec.end();
     ++i.first, ++i.second)
    {
        cout << i.first.first << "\n" << i.first.second << "\n" << i.second.second;
    }
    return 0; 
}

prog.cpp: In function 'int main()': prog.cpp:18:70: error: no matching function for call to 'std::pair, std::__cxx11::basic_string >, false, true>, std::__detail::_Node_iterator, bool>, false, true>

::pair(std::unordered_map, std::__cxx11::basic_string >::iterator, std::unordered_map, int>::iterator)' for (std::pair i(intVec.begin(), dubVec.begin()); ^ In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0, from /usr/include/c++/5/bits/char_traits.h:39, from /usr/include/c++/5/ios:40, from /usr/include/c++/5/ostream:38, from /usr/include/c++/5/iostream:39, from prog.cpp:3: /usr/include/c++/5/bits/stl_pair.h:206:9: note: candidate: template std::pair<_T1, _T2>::pair(std::tuple<_Args1 ...>&, std::tuple<_Args2 ...>&, std::_Index_tuple<_Indexes1 ...>, std::_Index_tuple<_Indexes2 ...>) pair(tuple<_Args1...>&, tuple<_Args2...>&, ^ /usr/include/c++/5/bits/stl_pair.h:206:9: note: template argument deduction/substitution failed: prog.cpp:18:70: note:
'std::unordered_map, std::__cxx11::basic_string >::iterator {aka std::__detail::_Node_iterator, std::__cxx11::ba

Aucun commentaire:

Enregistrer un commentaire