[llvm] r271757 - STLExtras: Add convenience is_contained() function.
Devin Coughlin via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 3 17:49:46 PDT 2016
Author: dcoughlin
Date: Fri Jun 3 19:49:46 2016
New Revision: 271757
URL: http://llvm.org/viewvc/llvm-project?rev=271757&view=rev
Log:
STLExtras: Add convenience is_contained() function.
This commit adds a convenience is_contained() function
which checks if an element exists in a container. It is part of a larger
series of patches adding an MPI checker to the clang static analyzer.
Reviewers: dblaikie,bkramer
A patch by Alexander Droste!
Differential Revision:http://reviews.llvm.org/D16053
Modified:
llvm/trunk/include/llvm/ADT/STLExtras.h
Modified: llvm/trunk/include/llvm/ADT/STLExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=271757&r1=271756&r2=271757&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/STLExtras.h (original)
+++ llvm/trunk/include/llvm/ADT/STLExtras.h Fri Jun 3 19:49:46 2016
@@ -412,6 +412,13 @@ auto remove_if(R &&Range, UnaryPredicate
return std::remove_if(Range.begin(), Range.end(), P);
}
+/// Wrapper function around std::find to detect if an element exists
+/// in a container.
+template <typename R, typename E>
+bool is_contained(R &&Range, const E &Element) {
+ return std::find(Range.begin(), Range.end(), Element) != Range.end();
+}
+
//===----------------------------------------------------------------------===//
// Extra additions to <memory>
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list