mardi 5 mai 2015

Compile error on std::list

Tried to compile the following code snippet on my ubuntu 12.04, using command g++ -std=c++11 te1.cc, (g++ version 4.7.3)

typedef unsigned int uint;
typedef std::unordered_map< uint, uint > imap;

void printTop (imap &m, int n=3) {
    std::list<uint> l;
    uint tmp;
    int size;
    for (auto kv: m) {
        size = l.size();
        if (size == 0) {
            l.push_front(kv.first);
            continue;
        }
        std::list<uint>::const_iterator it=l.begin();
        while (it != l.end()) {
            tmp = *it;
            if (kv.second >= m[tmp]) {
                tmp = kv.first;
                l.insert(it, tmp);
            }
        }
        if (l.size() > n) { l.pop_back();}
    }

}   

Got error:

error: no matching function for call to ‘std::list<unsigned int>::insert(std::list<unsigned int>::const_iterator&, uint&)’
te1.cc:29:21: note: candidates are:
In file included from /usr/include/c++/4.7/list:65:0,
                 from te1.cc:8:
/usr/include/c++/4.7/bits/list.tcc:99:5: note: std::list<_Tp, _Alloc>::iterator std::list<_Tp, _Alloc>::insert(std::list<_Tp, _Alloc>::iterator, const value_type&) [with _Tp = unsigned int; _Alloc = std::allocator<unsigned int>; std::list<_Tp, _Alloc>::iterator = std::_List_iterator<unsigned int>; std::list<_Tp, _Alloc>::value_type = unsigned int]
/usr/include/c++/4.7/bits/list.tcc:99:5: note:   no known conversion for argument 1 from ‘std::list<unsigned int>::const_iterator {aka std::_List_const_iterator<unsigned int>}’ to ‘std::list<unsigned int>::iterator {aka std::_List_iterator<unsigned int>}’
In file included from /usr/include/c++/4.7/list:64:0,

Any ideas?

Thanks.

Aucun commentaire:

Enregistrer un commentaire