Merging two std::map objects

Started by
1 comment, last by Fruny 18 years, 9 months ago
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?

Looking for a serious game project?
www.xgameproject.com
Advertisement
Do you mean something like A.insert(B.begin(), B.end()) ?
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());
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement