I want to create a map, that uses iterators as key-type and integers as values, like in the following example:
#include <list>
#include <unordered_map>
int main(int argc, char* argv[])
{
typedef std::list<int> ListType;
typedef std::unordered_multimap<ListType::iterator, unsigned int> MapType;
ListType _list;
MapType _map;
_list.push_back(100);
_map.insert(std::make_pair(_list.begin(), 10));
return 0;
}
Unfortunately, this makes the compiler aborting with the error C2440: 'conversion' : cannot convert from 'const std::_List_iterator<_Mylist>' to 'size_t'. Is there something i can do to achieve this anyway?
The error means you have to provide a hash function for the particular iterator type. You can pass a hashing function as third template parameter to std::unordered_map.
unordered_mapalso requires an equality comparator for its keys, however std::list’s iterator already has that, so you do not need to provide your own. For example: