Since you are dealing with std::set
, a union can be built by simply adding elements of the two sets together, like this:
set<int> a {1,2,3,4};
set<int> b {3,4,5,6};
// Copy the first set
set<int> u(a);
// Add elements of the second set to the copy to get a union
u.insert(b.begin(), b.end());
Here is a demo on ideone.
solved SetUnion: set