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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:13:30+00:00 2026-06-07T00:13:30+00:00

The standard specifies (23.4.4.2:5, etc.) that constructing all four ordered associative containers ( map

  • 0

The standard specifies (23.4.4.2:5, etc.) that constructing all four ordered associative containers (map, multimap, set, multiset) from a range [first, last) shall be linear in N = last - first if the range is already sorted.

For merging a range (e.g. a container of the same type) into an existing container, however, 23.2.4:8 table 102 specifies only that inserting a range [i, j) into the container shall have complexity N log(a.size() + N) where N = distance(i, j). This would seem to indicate that using the hinted insert:

for (auto it = a.begin(); i != j; ++i)
    it = next(a.insert(it, *i));

could be more efficient than a.insert(i, j), having complexity strictly less than N log(a.size() + N), depending on the proportion of hints that are correct (except in the trivial case where N == 0); and being linear, since every hint is correct, if a is initially empty.

Is this a deficiency in the standard, or is there some other language (or facility) that covers this case? In practice, do implementations optimise for merging an ordered associative container into another?

Credit to https://stackoverflow.com/a/11362162/567292 for inspiring this question.

  • 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-07T00:13:31+00:00Added an answer on June 7, 2026 at 12:13 am

    I would assume in the latter case that the standard is only specifying the worst-case guaranteed run-time performance of the associative container merge, leaving it up to the implementation to find faster performance short-cuts if they are possible. Keep in mind that unlike other languages, the C++ specification is exactly that – a spec. There is no “reference” implementation. Thus one could write an implementation that only meets certain performance criteria, or one could decide to implement features that would exceed the specified performance criteria. In the end though the specification is designed to give you an “at minimum” performance guarantee in the way certain algorithms are implemented.

    That being said, should you always use hinting for every element, your worst-case performance actually ends up being twice as slow as if you had simply inserted without hinting. So always using hinting is not necessarily a panacea.

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

Sidebar

Related Questions

All operations on standard signed integer types in C (short, int, long, etc) exhibit
In standard SQL, is there a way to say: select mubmle as x from
The standard explicitly states that main has two valid (i.e., guaranteed to work) signatures;
I have code that manipulates binary files using fstream with the binary flag set
I'm trying to set up an enumeration that maps certain project-specific values to the
I have a standard insert into / select statement that is formatted similar to
I need to parse .PEM files. I know that the standard for Privacy-enhanced Electronic
I have a MultiLine asp:Textbox (a standard html textarea for those non-asp people) that
I used to use the standard mysql_connect(), mysql_query(), etc statements for doing MySQL stuff
I have a Native WinApi C++ Application that finds media(.wmv, .mp3 etc.) files in

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.