[PATCH] D18281: [SetVector] Add erase() method

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 18 14:16:02 PDT 2016


Test coverage?

On Fri, Mar 18, 2016 at 2:14 PM, Jun Bum Lim via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> junbuml created this revision.
> junbuml added reviewers: MatzeB, qcolombet, mcrosier.
> junbuml added a subscriber: llvm-commits.
> Herald added a subscriber: mcrosier.
>
> Add erase() which returns an iterator pointing to the next element after
> the
> erased one. This makes it possible to erase selected elements while
> iterating
> over the SetVector :
>   while (I != E)
>     if (test(*I))
>       I = SetVector.erase(I);
>     else
>       ++I;
>
> http://reviews.llvm.org/D18281
>
> Files:
>   include/llvm/ADT/SetVector.h
>
> Index: include/llvm/ADT/SetVector.h
> ===================================================================
> --- include/llvm/ADT/SetVector.h
> +++ include/llvm/ADT/SetVector.h
> @@ -151,6 +151,21 @@
>      return false;
>    }
>
> +  /// \brief Erase a single element from the set vector.
> +  /// \returns an iterator pointing to the next element that followed the
> +  /// element erased. This is the end of the SetVector if the last
> element is
> +  /// erased.
> +  iterator erase(iterator I) {
> +    const key_type &V = *I;
> +    typename vector_type::iterator VI =
> +        std::find(vector_.begin(), vector_.end(), V);
> +    assert(VI != vector_.end() && "Iterator to erase is out of bounds.");
> +    if (!set_.erase(V)) {
> +      assert(false && "Corrupted SetVector instances!");
> +    }
> +    return vector_.erase(VI);
> +  }
> +
>    /// \brief Remove items from the set vector based on a predicate
> function.
>    ///
>    /// This is intended to be equivalent to the following code, if we could
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160318/af773dca/attachment.html>


More information about the llvm-commits mailing list