jeudi 30 avril 2015

Insertion in an unordered_multimap

The following code compiles:

unordered_multimap<int, string> Map;
Map.insert( {{1, "1"}, {1, "1"}} );

... but this does not:

unordered_multimap<int, string> Map;
Map.insert( {{1, "1"}} );

I use VS13 and the error I get is

test.cpp(1170): error C2668: 'std::unordered_multimap<int,std::string,std::hash<int>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>::insert' : ambiguous call to overloaded function
          with
          [
              _Kty=int
  ,            _Ty=std::string
          ]
          c:\program files (x86)\microsoft visual studio 12.0\vc\include\unordered_map(619): could be 'std::_List_iterator<std::_List_val<std::_List_simple_types<std::pair<const _Kty,_Ty>>>> std::unordered_multimap<_Kty,_Ty,std::hash<int>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>::insert(const std::pair<const _Kty,_Ty> &)'
          with
          [
              _Kty=int
  ,            _Ty=std::string
          ]
          c:\program files (x86)\microsoft visual studio 12.0\vc\include\unordered_map(604): or       'void std::unordered_multimap<int,std::string,std::hash<int>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,_Ty>>>::insert(std::initializer_list<std::pair<const _Kty,_Ty>>)'
          with
          [
              _Kty=int
  ,            _Ty=std::string
          ]
          while trying to match the argument list '(initializer-list)'

Any idea what's going on??

Aucun commentaire:

Enregistrer un commentaire