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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:46:58+00:00 2026-06-12T07:46:58+00:00

If I have a map/multimap with keys inserted using a comparison function (functor), is

  • 0

If I have a map/multimap with keys inserted using a comparison function (functor), is it possible to use map::equal_range with a comparison function as well? For instance, if I have a std::map m, and keys:

sometype a.getVal == 101
sometype b.getVal == 112 <-first pair (using equal_range)
sometype c.getVal == 113
sometype d.getVal == 121 <-second pair (using equal_range)

and I wanted to get a range/set of keys 11* is that possible?

  • 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-12T07:46:59+00:00Added an answer on June 12, 2026 at 7:46 am

    There is a good reason why you cannot use map::equal_range() with a custom comparer: it would defeat the asociativity of the container. It can be done, but the algorithm would be O(n) instead of O(log(n)), since it would have to compare all map elements regardless of their position.

    I think the best solution for your problem would be a custom function that uses map::lower_bound() and map::upper_bound() to find your interval limits. Something like:

    typedef std::map<int>::iterator Iter;
    std::pair<Iter, Iter> CustomEqualRange (const std::map<int>& theMap, int lowerBound, int range)
    {
      Iter lower = theMap.lower_bound(lowerBound);
      Iter upper = theMap.upper_bound(lowerBound + range);
      return std::make_pair(lower, upper);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strongly recursive function, that creates a (very small) std::multimap locally for
I have a std::multimap on which I am iterating using a forward iterator. std::multimap<int,char>::iterator
I have a map using the multimap trait, like so val multiMap = new
I have a std::multimap , and I want to create a boost::iterator_range from equal_range
I have a multimap defined by typedef std::pair<int, int> comp_buf_pair; //pair<comp_t, dij> typedef std::pair<int,
I have a multimap defined by typedef std::pair<int, int> au_pair; //vertices typedef std::pair<int, int>
I have a STL::multimap and I search it with equal_range to return an upper
In my Map application I have segment controller on main screen and using that
I would like to have a c.g.c.c.Multimap that is sorted based on keys only.
I have a MultiMap and need the best possible way to get an EntrySet

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.