[PATCH] D16053: is_contained() convenience function

Alexander Droste via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 17 13:28:08 PST 2016


Alexander_Droste retitled this revision from "contains() convenience function" to "is_contained() convenience function".
Alexander_Droste updated this revision to Diff 45115.
Alexander_Droste added a comment.

- changed implementation to `std::equal_to<>` style


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);
 }
 
+/// Wrapper function around llvm::any_of to detect if an element exists
+/// in a container.
+template <typename R, typename E>
+bool is_contained(R &&Range, const E &Element) {
+    return any_of(Range, bind2nd(std::equal_to<E>(), Element));
+}
+
 //===----------------------------------------------------------------------===//
 //     Extra additions to <memory>
 //===----------------------------------------------------------------------===//


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16053.45115.patch
Type: text/x-patch
Size: 699 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160117/6dee7f70/attachment.bin>


More information about the llvm-commits mailing list