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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:14:31+00:00 2026-05-24T23:14:31+00:00

I have a Map::const_iterator object in C++ and i am trying to abstract the

  • 0

I have a Map::const_iterator object in C++ and i am trying to abstract the entire map object from it without explicitly creating a map with Map::const_iterator->first and Map::const_iterator->second.

this doesn’t seem to work : (*Map::const_iterator).as_map()
please advice.

  • 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-05-24T23:14:32+00:00Added an answer on May 24, 2026 at 11:14 pm

    I’m afraid I understood the question totally wrong. How about using it->second?

     typedef .... mymap_t;
     typedef std::map<std::string, mymap_t> supermap_t;
    
     supermap_t supermap;
    
    
     for (supermap_t::const_iterator it = supermap.begin();
              it != supermap.end();
              ++it)
     {
         const mymap& the_sub_map = it->second;
         call_some_other_function(the_sub_map); // the whole submap
     }
    


    From the question it is hard to make out what you actually need, but I’m going to guess that you are looking for a way to treat an iterator range as a container, without having to copy the container.

    Have a look at Boost Range for that.

     typedef map<int, string> mymap_t;
    
     mymap_t mymap;
     mymap[1] = "One";
     mymap[2] = "Two";
     mymap[3] = "Three";
    
     mymap_t::const_iterator first(my_map.begin()), 
                             last(my_map.end());
    
     boost::sub_range<mymap_t> subrange(first++, last); // contains two items
    

    You could treat subrange as a ‘container’ class with boost range algorithms.

    Does this come close to what you wanted to ask?

    Update

    It seems you are after this:

     typedef map<int, string> mymap_t;
    
     void somefunction(mymap_t::const_iterator first, mymap_t::const_iterator last)
     {
         mymap_t subclone(first, last);
    
         // use subclone -- it is a mymap_t now :)
     } 
    
     mymap_t mymap;
     mymap[1] = "One";
     mymap[2] = "Two";
     mymap[3] = "Three";
    
     somefunction(mymap.begin(), mymap.end());
    

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

Sidebar

Related Questions

in my function, i have this parameter: map<string,int> *&itemList I want to first check
I have a map defined like this std::map<some_key_type, std::string::iterator> mIteratorMap; And a huge string
I have a map that represents a DB object. I want to get 'well
I have an object: map<A*, string> collection; I would like to call the map::find
I have the following code: map<StatTypesEnum, ValueHandler*>::const_iterator itr; for(itr=player1->Stats.begin(); itr!=player1->Stats.end(); itr++) { cout <<
I have a std::map of Poco::Any which I'm trying to iterate and output to
The Context I have a custom template container class put together from a map
I have a map which contains integer values. i want to re-arange this map
When I have a template class which contains template map and a const_iterator declared
Continuing from my last question C++ template class map I have implemented the function

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.