summaryrefslogtreecommitdiffstats
path: root/llvm/include/llvm/ADT/STLExtras.h
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/include/llvm/ADT/STLExtras.h')
-rw-r--r--llvm/include/llvm/ADT/STLExtras.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 274933bc520..430707cbd79 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1573,6 +1573,14 @@ template <class Ptr> auto to_address(const Ptr &P) -> decltype(P.operator->()) {
}
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
OpenPOWER on IntegriCloud