[PATCH] D15064: Introduce a range version of std::find, and use in SCEV

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 29 17:28:04 PST 2015


sanjoy created this revision.
sanjoy added reviewers: dblaikie, pcc.
sanjoy added a subscriber: llvm-commits.

http://reviews.llvm.org/D15064

Files:
  include/llvm/ADT/STLExtras.h
  lib/Analysis/ScalarEvolution.cpp

Index: lib/Analysis/ScalarEvolution.cpp
===================================================================
--- lib/Analysis/ScalarEvolution.cpp
+++ lib/Analysis/ScalarEvolution.cpp
@@ -7964,8 +7964,7 @@
   const MaxExprType *MaxExpr = dyn_cast<MaxExprType>(MaybeMaxExpr);
   if (!MaxExpr) return false;
 
-  auto It = std::find(MaxExpr->op_begin(), MaxExpr->op_end(), Candidate);
-  return It != MaxExpr->op_end();
+  return find(MaxExpr->operands(), Candidate) != MaxExpr->op_end();
 }
 
 
Index: include/llvm/ADT/STLExtras.h
===================================================================
--- include/llvm/ADT/STLExtras.h
+++ include/llvm/ADT/STLExtras.h
@@ -379,6 +379,13 @@
                      std::forward<UnaryPredicate>(P));
 }
 
+/// Provide wrappers to std::find which take ranges instead of having to pass
+/// begin/end explicitly.
+template<typename R, class T>
+auto find(R &&Range, const T &val) -> decltype(Range.begin()) {
+  return std::find(Range.begin(), Range.end(), val);
+}
+
 //===----------------------------------------------------------------------===//
 //     Extra additions to <memory>
 //===----------------------------------------------------------------------===//


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15064.41361.patch
Type: text/x-patch
Size: 1205 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151130/0d2c3028/attachment.bin>


More information about the llvm-commits mailing list