[llvm] [ADT] Teach set_intersect to erase with iterators (PR #99569)

Jakub Kuderski via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 18 15:27:55 PDT 2024


================
@@ -60,6 +60,13 @@ template <class S1Ty, class S2Ty> void set_intersect(S1Ty &S1, const S2Ty &S2) {
   auto Pred = [&S2](const auto &E) { return !S2.count(E); };
   if constexpr (detail::HasMemberRemoveIf<S1Ty, decltype(Pred)>) {
     S1.remove_if(Pred);
+  } else if constexpr (detail::HasMemberEraseIter<S1Ty>) {
+    typename S1Ty::iterator Next;
+    for (typename S1Ty::iterator I = S1.begin(); I != S1.end(); I = Next) {
+      Next = std::next(I);
----------------
kuhar wrote:

nit: Just below we call `++I`. Do we need the `std::next` then?

https://github.com/llvm/llvm-project/pull/99569


More information about the llvm-commits mailing list