Merge multiple sets elements in a single set

codeJack picture codeJack · Aug 17, 2011 · Viewed 64.4k times · Source

I would like to know if there is any std library or boost tool to easily merge the contents of multiple sets into a single one.

In my case I have some sets of ints which I would like to merge.

Answer

Nicola Musatti picture Nicola Musatti · Aug 17, 2011

You can do something like:

std::set<int> s1;
std::set<int> s2;
// fill your sets
s1.insert(s2.begin(), s2.end());