AwaitedOne
AwaitedOne

Reputation: 1012

unordered_map, no match function call error

The example program of unordered_map when I run in Linux terminal using c++11 or c++17, it works fine. I tried the same program in eclipse Neon.1a Release(4.6.1) using c++11 or c++17, gives many error messages including

no matching function for call to ‘boost::unordered::unordered_map >::insert(int, std::pair)’ refmap.insert(1, std::make_pair(2,5));

#include <iostream>
#include <boost/unordered_map.hpp>
#include <utility>
typedef boost::unordered_map<int, std::pair<int, int> > reference_map;
reference_map refmap;
int main(){

        refmap.insert(1, std::make_pair(2,5));
        return 0;
    }

Upvotes: 0

Views: 1605

Answers (1)

ildjarn
ildjarn

Reputation: 62995

insert takes a single argument, not two – a std::pair<K const, V> (aka std::unordered_map<K,V>::value_type):

int main() {
    refmap.insert(std::make_pair(1, std::make_pair(2, 5)));
}

The function taking separate arguments for key and value is named emplace, and should be preferred in most cases:

int main() {
    refmap.emplace(1, std::make_pair(2, 5));
}

Online Demo

Upvotes: 2

Related Questions