Introduce a range version of std::find, and use in SCEV
authorSanjoy Das <sanjoy@playingwithpointers.com>
Tue, 1 Dec 2015 07:49:27 +0000 (07:49 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Tue, 1 Dec 2015 07:49:27 +0000 (07:49 +0000)
Reviewers: dblaikie, pcc

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D15064

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254391 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 3655a20d8831816352bf42acc7eb9ee5d231bfe4..d4360fa8d218d9859c48bbcc69ce7ebe9b056b6c 100644 (file)
@@ -379,6 +379,13 @@ bool any_of(R &&Range, UnaryPredicate &&P) {
                      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>
 //===----------------------------------------------------------------------===//
index 4c8b6e7de84e660cbdc7531e0f6dc64e2c2fce20..d04028b15e2fa6adc58ce92c61c1636ea5a53128 100644 (file)
@@ -7964,8 +7964,7 @@ static bool IsMaxConsistingOf(const SCEV *MaybeMaxExpr,
   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();
 }