[PATCH] D16053: contains() convenience function

Alexander Droste via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 11 02:08:43 PST 2016


Alexander_Droste created this revision.
Alexander_Droste added subscribers: llvm-commits, zaks.anna, dcoughlin.

This patch adds a convenience `contains()` function 
which checks if an element exists in a container.

http://reviews.llvm.org/D16053

Files:
  include/llvm/ADT/STLExtras.h

Index: include/llvm/ADT/STLExtras.h
===================================================================
--- include/llvm/ADT/STLExtras.h
+++ include/llvm/ADT/STLExtras.h
@@ -386,6 +386,13 @@
   return std::find(Range.begin(), Range.end(), val);
 }
 
+/// Returns true if \p Container contains \p Element.
+template <typename T, typename E>
+bool contains(const T &Container, const E &Element) {
+  return std::find(Container.begin(), Container.end(), Element) !=
+         Container.end();
+}
+
 //===----------------------------------------------------------------------===//
 //     Extra additions to <memory>
 //===----------------------------------------------------------------------===//


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16053.44448.patch
Type: text/x-patch
Size: 695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160111/be087247/attachment.bin>


More information about the llvm-commits mailing list