What's the return of the algorithm std:set_union when one or both input containers are multisets with duplicated objects? Do dups get lost?
Let's suppose for example:
multiset<int> ms1;
ms1.insert(1);
ms1.insert(1);
ms1.insert(1);
ms1.insert(2);
ms1.insert(3);
multiset<int> ms2;
ms2.insert(1);
ms2.insert(1);
ms2.insert(2);
ms2.insert(2);
ms2.insert(4);
vector<int> v(10);
set_union( ms1.begin(), ms1.end(), ms2.begin(), ms2.end(), v.begin() );
What would the output be?
From the C++ standard, §25.3.5/1:
From the standard, 25.3.5:
So in your example, the result will be (1,1,1,2,2,3,4,0,0,0), since you initialised the vector with length 10.
From the documentation of std::set_union (emphasis added).
It will appear
max(m,n)
times wherem
is the number of times it occurs inms1
andn
is the number of times it occurs inms2
.