[llvm] r373034 - [Consumed][NFC] Refactor handleCall to take function argument list.
Nicholas Allegra via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 26 16:47:18 PDT 2019
Author: comex
Date: Thu Sep 26 16:47:18 2019
New Revision: 373034
URL: http://llvm.org/viewvc/llvm-project?rev=373034&view=rev
Log:
[Consumed][NFC] Refactor handleCall to take function argument list.
Differential Revision: https://reviews.llvm.org/D67569
Modified:
llvm/trunk/include/llvm/ADT/STLExtras.h
llvm/trunk/include/llvm/ADT/iterator_range.h
Modified: llvm/trunk/include/llvm/ADT/STLExtras.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/STLExtras.h?rev=373034&r1=373033&r2=373034&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/STLExtras.h (original)
+++ llvm/trunk/include/llvm/ADT/STLExtras.h Thu Sep 26 16:47:18 2019
@@ -1573,6 +1573,14 @@ template <class Ptr> auto to_address(con
}
template <class T> constexpr T *to_address(T *P) { return P; }
+template <typename R>
+auto index(R &&TheRange,
+ typename std::iterator_traits<detail::IterOfRange<R>>::difference_type N)
+ -> decltype(TheRange.begin()[N]) {
+ assert(N < TheRange.end() - TheRange.begin() && "Index out of range!");
+ return TheRange.begin()[N];
+}
+
} // end namespace llvm
#endif // LLVM_ADT_STLEXTRAS_H
Modified: llvm/trunk/include/llvm/ADT/iterator_range.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/iterator_range.h?rev=373034&r1=373033&r2=373034&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/iterator_range.h (original)
+++ llvm/trunk/include/llvm/ADT/iterator_range.h Thu Sep 26 16:47:18 2019
@@ -20,9 +20,17 @@
#include <iterator>
#include <utility>
+#include <cassert>
namespace llvm {
+template <typename T>
+constexpr bool is_random_iterator() {
+ return std::is_same<
+ typename std::iterator_traits<T>::iterator_category,
+ std::random_access_iterator_tag>::value;
+}
+
/// A range adaptor for a pair of iterators.
///
/// This just wraps two iterators into a range-compatible interface. Nothing
@@ -58,11 +66,31 @@ template <typename T> iterator_range<T>
return iterator_range<T>(std::move(p.first), std::move(p.second));
}
+/// Non-random-iterator version
template <typename T>
-iterator_range<decltype(adl_begin(std::declval<T>()))> drop_begin(T &&t,
- int n) {
- return make_range(std::next(adl_begin(t), n), adl_end(t));
+auto drop_begin(T &&t, int n) ->
+ typename std::enable_if<!is_random_iterator<decltype(adl_begin(t))>(),
+ iterator_range<decltype(adl_begin(t))>>::type {
+ auto begin = adl_begin(t);
+ auto end = adl_end(t);
+ for (int i = 0; i < n; i++) {
+ assert(begin != end);
+ ++begin;
+ }
+ return make_range(begin, end);
}
+
+/// Optimized version for random iterators
+template <typename T>
+auto drop_begin(T &&t, int n) ->
+ typename std::enable_if<is_random_iterator<decltype(adl_begin(t))>(),
+ iterator_range<decltype(adl_begin(t))>>::type {
+ auto begin = adl_begin(t);
+ auto end = adl_end(t);
+ assert(end - begin >= n && "Dropping more elements than exist!");
+ return make_range(std::next(begin, n), end);
+}
+
}
#endif
More information about the llvm-commits
mailing list