From 7cb374882d3754d445c9adfd6255a8292ce3353b Mon Sep 17 00:00:00 2001 From: Devin Coughlin Date: Sat, 4 Jun 2016 00:49:46 +0000 Subject: [PATCH] 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 llvm-svn: 271757 --- llvm/include/llvm/ADT/STLExtras.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index 11be19607f86..72682f8ae1eb 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -412,6 +412,13 @@ auto remove_if(R &&Range, UnaryPredicate &&P) -> decltype(Range.begin()) { return std::remove_if(Range.begin(), Range.end(), P); } +/// Wrapper function around std::find to detect if an element exists +/// in a container. +template +bool is_contained(R &&Range, const E &Element) { + return std::find(Range.begin(), Range.end(), Element) != Range.end(); +} + //===----------------------------------------------------------------------===// // Extra additions to //===----------------------------------------------------------------------===//