c++stlsetstdset

How to merge multiple sets into a single std::set (set union)


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 set<int>s which I would like to merge.


Solution

  • You can do something like:

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