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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:30:13+00:00 2026-05-25T19:30:13+00:00

[ Preface: The associative C++ containers like std::map are a bit like micro-databases with

  • 0

[Preface: The associative C++ containers like std::map are a bit like micro-databases with just one key column. Boost’s bimap elevates this to a two-column table with lookup in both columns, but that that’s as far as the analogy goes — there’s no “polymap” that generalizes the idea.]

In any event, I want to keep thinking of maps as databases, and I now wonder if there is an iterator (or some other solution) that allows me to do a UNION of several constituent maps. That is, all maps have the same type (or value type and comparator, at least), and I want a single iterator that treats the entire collection as a big multimap (repeated keys are OK) and lets me traverse it in the correct unioned order.

Does such a thing exist, perhaps within Boost? Or is it easy to rig one up? In pseudo code:

std::map<K, M> m1, m2;
union_iterator<K, M> u(m1, m2)
for(auto it = u.begin(); it != u.end(); ++it) { /* ... */ }

For example, if we had:

m1 = { { 9:00, "Check in"}, { 12:00, "Break" }, { 16:00, "Check out"} };
m2 = { { 10:30, "coffee" }, { 12:15, "baked beans" }, { 15:00, "lies" } };

then I want the iterator to produce:

9:00, "Check in"; 10:30, "coffee"; 12:00, "Break"; 12:15, "baked beans"; ...
  • 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-25T19:30:13+00:00Added an answer on May 25, 2026 at 7:30 pm

    As I announced, I have got something pretty cool.

    I’m posting it now, because I wouldn’t be sure whether I’d be back in time tonight to post it. I will be spending a few words in explanation. (in this post)

    PS. The includes will be trimmed down (to about 20%); I will probably do some more general work on the code too.

    A lot can be said about this code: it is not very efficient, and not very clean (yet). It is, however, nearly infinitely generic and should scale like anything else. All code can be found in a github gist:

    • merge_maps_iterator.hpp
    • Makefile
    • test.cpp – a rather arcane set of test-cases showing off the genericity
      (I’m not saying that it would be a good idea to have maps keyed with ints and floats (let alone both at the same time) – just showing that it can be done)

    Here is the output of the test.cpp as you can find it:

     == input ========================================
    { 2, aap }      { 23, mies }    { 100, noot }   { 101, broer }  
    { b, 3.14 }     
     == output =======================================
         2: aap;
        23: mies;
        98: 3.14;
       100: noot;
       101: broer;
    
     == input ========================================
    { b, 3.14 }     
    { 2, aap }      { 23, mies }    { 100, noot }   { 101, broer }  
     == output =======================================
         2: aap;
        23: mies;
        98: 3.14;
       100: noot;
       101: broer;
    
     == input ========================================
    { 2, aap }      { 23, mies }    { 100, noot }   { 101, broer }  
    { 2, aap }      { 23, mies }    { 100, noot }   { 101, broer }  
     == output =======================================
         2: aap;aap;
        23: mies;mies;
       100: noot;noot;
       101: broer;broer;
    
     == input ========================================
    { b, 3.14 }     
    { b, 3.14 }     
     == output =======================================
         b: 3.14;3.14;
    
     == input ========================================
    { 1.0, dag }    { 22.0, bye }   { 24.0, Tschüß }
    { 1, true }     { 22, false }   { 24, true }    
    { b, 3.14 }     
    { 2, aap }      { 23, mies }    { 100, noot }   { 101, broer }  
     == output =======================================
       1.0: dag;true;
       2.0: aap;
      22.0: bye;false;
      23.0: mies;
      24.0: Tschüß;true;
      98.0: 3.14;
     100.0: noot;
     101.0: broer;
    
     == input ========================================
    { 1.0, dag }    { 2.0, EXTRA }  { 22.0, bye }   { 24.0, Tschüß }
    { 1, true }     { 22, false }   { 24, true }    
    { b, 3.14 }     
    { 2, aap }      { 23, mies }    { 100, noot }   { 101, broer }  
     == output =======================================
       1.0: dag;true;
       2.0: EXTRA;aap;
      22.0: bye;false;
      23.0: mies;
      24.0: Tschüß;true;
      98.0: 3.14;
     100.0: noot;
     101.0: broer;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Preface: I'm a big fan of Netbeans for Rails development. I'm just starting my
Preface: I have two entities defined as a one-to-many relationship: A <<-------> B. B's
Preface: Please don't start a discussion on premature optimization, or anything related. I'm just
PREFACE: Yes we're moving away from VSS in the next few months. One of
preface note: I'm just starting to learn Grails, so I'm sure there are many
Preface: I'm a total Java noob...I just wrote Hello World yesterday. Have mercy on
Let me preface this by saying that I know the ContactCenter sample is just
Preface : I am new to the iPhone SDK, Obj-C, Interface Builder and Cocoa.
Preface : I'm honestly not sure if this should be on StackOverflow, SuperUser or
Preface: I'm posting this on behalf of a friend (who's apparently to shy to

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.