Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8041353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:11:13+00:00 2026-06-05T04:11:13+00:00

I want to create a map, that uses iterators as key-type and integers as

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T04:11:15+00:00Added an answer on June 5, 2026 at 4:11 am

    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_map also 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:

    #include <list>
    #include <unordered_map>
    #include <cstddef>
    
    typedef std::list<int> ListType;
    typedef std::list<int>::iterator ListIterator;
    // a very poor hashing functor
    struct MyHash {
      size_t operator()(const ListIterator&) const {
        // provide a useful implementation here!
        size_t hash_ = .... ;
        return hash_;
        //return 0; // compiles, but is useless
      }
    };
    
    typedef std::unordered_multimap<ListIterator, unsigned int, MyHash> MapType;
    
    int main() {
    
      ListType list_;
      MapType map_;
    
      list_.push_back(100);
      map_.insert(std::make_pair(list_.begin(), 10));
    
      return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a Map object that can lose value only if we
I want to create a function that can take different types of iterators which
We want to use MapKit / MKOverlayView to create a map that looks totally
I want to sort elements in map container using only values not key. how
I want to create an app that uses both MongoDB and MySQL. Specifically, I
I want to create a map that will provide the benefits of generics, whilst
I'd like to use a map that would be equivalent to ConcurrentMap (I want
I want to create application which would display spatial data on Map. I'm thinking
I am using oozie to run my map-reduce job. I want to create the
I want create module which update list of usb devices automatically (not only mass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.