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 8639141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:55:32+00:00 2026-06-12T10:55:32+00:00

Why can a map of vector::iterator to int be defined but a map of

  • 0

Why can a map of vector::iterator to int be defined but a map of list::iterator to int cannot?

#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;


int main()
{
    int ia[] = {1,2,3,4,5,6,7,8,9,0};

    vector<int> v(begin(ia), end(ia));
    auto it1 = find(begin(v), end(v), 4);
    map< vector<int>::const_iterator, int > m1;
    m1.insert(map<vector<int>::const_iterator, int>::value_type(it1,*it1));

    list<int> l(begin(ia), end(ia));
    auto it2 = find(begin(l), end(l),5);
    map< list<int>::const_iterator, int> m2;
    m2.insert(map<list<int>::const_iterator, int>::value_type(it2,*it2)); //doesn't compile

}

Error 1 error C2678: binary ‘<‘ : no operator found which takes a left-hand operand of type ‘const std::_List_const_iterator<_Mylist>’ (or there is no acceptable conversion)

  • 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-12T10:55:33+00:00Added an answer on June 12, 2026 at 10:55 am

    std::map requires that the key be comparable, either with <, or a provided comparator.

    Conceptually, random-access iterators are comparable, but bidirectional iterators aren’t. std::vector iterators are random access, and std::list iterators are bidirectional.

    So, your list iterator doesn’t satisfy the comparable requirement of a std::map key type. If you provide a comparator which can usefully decide which std::list::const_iterator should come before another, you can pass it to the map and this will work. Rough sketch:

    struct ListIterCmp {
        bool operator() (list<int>::const_iterator a, list<int>::const_iterator b)
        {
            // how?
        }
    };
    map< list<int>::const_iterator, int, ListIterCmp> m2;
    // this should work now...
    

    The cppreference documentation covers everything I used to use the old SGI docs for, and is still updated. See that both describe a<b for the RandomAccessIterator, and not for the BidirectionalIterator concept.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While iterating through a std::map or std::vector or any container which has iterator in
How can I map the value of an object collection using fluent mapping? I
I don't know what's make wrong, my map can load, but the image on
I have image map that can I move, but this map will be so
I have a multimap defined by typedef std::pair<int, int> au_pair; //vertices typedef std::pair<int, int>
I have the following cyclic dependency problem I am trying to solve: typedef std::map<int,
I'm trying to encapsulate the C++ Standard Library's vector class using templates but I
map<string,string>::find seems to be returning garbage iterator, since i can access neither my_it->first nor
I have a vector-layer for displaying markers as features on my map, but now
I am trying to map a 1D array onto 3D array using provided list

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.