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

  • Home
  • SEARCH
  • 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 981089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:29:12+00:00 2026-05-16T04:29:12+00:00

I have got a std::list< std::pair<std::string,double> > , which I know is sorted according

  • 0

I have got a std::list< std::pair<std::string,double> >, which I know is sorted according to the std::string element.

Since I would like to do a lot of std::find_if based on the std::string element, I believe a std::map<string,double,MyOwnBinaryPredicate> with lower_bound and upper_bound would be more adequate.

The fact is that I want to insert elements in the std::map in an efficient way. So I want to use an additional iterator to make the insert faster.

I believe the easiest way would be to use a const_reverse_iterator to go through the std::list and to use the begin() of the std::map.

Would you do it this way, or is it a bad idea?

Thanks!

  • 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-16T04:29:12+00:00Added an answer on May 16, 2026 at 4:29 am

    If you already have a sorted list, which is sorted according to the predicate Predicate, you can just do the following:

    std::list< std::pair<std::string, double> > sorted_list;
    std::map<string, double, Predicate> map(sorted_list.begin(), sorted_list.end());
    

    The map constructor has linear time complexity if your list is already sorted, O(n*log n) otherwise. You can then work directly with the map as you would any other.

    If you later want the results back in your list you could just do the opposite:

    sorted_list.assign(map.begin(), map.end());
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Sounds like you have a lot of reading to do.… May 16, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer The qt-designer is inside the new qtcreator (former package was… May 16, 2026 at 4:00 pm
  • Editorial Team
    Editorial Team added an answer It turned out that the code beneath the redirect was… May 16, 2026 at 4:00 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have a class that contains, among other things, an std::list. I want to
I've got a unit test I'm writing which seems to have some kind of
I have an stl unordered_map and I would like to store references to elements
I have got the following issue, my function appends code to a string $string
So I've got an app which compiles fine on windows, linux and a few
I have got ListView with a custom Adapter. Every row contains clickable buttons and
I have got a problem on casting an object to one of it's base
I have a little class called Stuff that I want to store things in.
I've got a really odd error message that only occurs when I add the
Possible Duplicate: Copy a linked list Hello stackoverflow! I am trying to learn more

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.