• Advertisement
Sign in to follow this  

Merging two std::map objects

This topic is 4667 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Supposing I have two std::map<X,Y> objects A and B. I want to create another one, C, which would contain all the elements contained in A and B, what is the simplest way to do this? Alternatively, is there a direct way to copy the elements from B into A?

Share this post


Link to post
Share on other sites
Advertisement
std::map<Foo,Bar> a;
std::map<Foo,Bar> b;
std::map<Foo,Bar> c;

c.insert(a.begin(), a.end());
c.insert(b.begin(), b.end());

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement