auto remove_missing = [](auto first1, auto last1, auto first2, auto last2, auto comp)
{
return std::remove_if(
first1, last1,[&](auto const& elem)
{ return not std::binary_search(first2, last2, elem, comp); }
);
};
I suggest the algorithm above with the name remove_missing. It is quite similar to std::set_intersection(_copy).
The implementation above has complexity O(N*log(M)). N = size of first1..last1 and M = size of first2..last2
A better implementation is
auto remove_missing = [](auto first1, auto last1, auto first2, auto last2, auto comp)
{
auto out = first1;
while (first1 != last1 && first2 != last2)
{
if (comp(*first1, *first2))
++first1;
else
{
if (!comp(*first2, *first1))
*out++ = *first1++; // *first1 and *first2 are equivalent.
else // THE else IS NEW
++first2;
}
}
return out;
};
which has Complexity O(N+M).
Are people interested in putting this algo into the standard?
My test project is here