This patch adds a couple of unit tests:
- SetSubtractSmallPtrSet exercises the code path involving remove_if,
added in d772cdd6279de1e578dfdfca7432327a1806c659. Note that
SmallPtrSet supports remove_if.
- SetSubtractSmallVector exercises the code path involving
S1.erase(*SI) and ensures that set_subtract continues to accept S2
being a vector, which does not have contains.
The current set_intersect implementation only works for std::set style
sets that have a value-erase method that does not invalidate iterators.
As such, it cannot be used for set containers like SetVector, which only
has iterator-invalidating erase.
Support such set containers by calling the remove_if method instead, if
it exists. The detection code is adopted from how contains() is detected
inside llvm::is_contained().
New set operations split out of D140908 as suggested, and I have added
unit testing for all set operations.
This adds a set_intersection, which returns the intersection instead of
updating the first set like set_intersect (using a different name
analogous to set_difference vs set_subtract).
Also adds a variant of set_subtract that updates two additional set
arguments to note which members of the subtrahend were removed from
the minuend and which were not.
Differential Revision: https://reviews.llvm.org/D144220