From fc9aa33def002ad03f6f9102a2833e0476b5d7b5 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 21 Jun 2019 05:43:08 +0000 Subject: [PATCH] Use std::iterator_traits to infer result type of llvm::enumerate iterator wrapper Update the llvm::enumerate helper class result_pair to use the 'iterator_traits::reference' type as the result of 'value()' instead 'ValueOfRange &'. This enables support for iterators that return value types, i.e. non reference. This is a common pattern for some classes of iterators, e.g. mapped_iterator. Patch by: River Riddle Differential Revision: https://reviews.llvm.org/D63632 llvm-svn: 364007 --- llvm/include/llvm/ADT/STLExtras.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index eb9dff3efeda..de82f2bce7f8 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -1506,6 +1506,9 @@ namespace detail { template class enumerator_iter; template struct result_pair { + using value_reference = + typename std::iterator_traits>::reference; + friend class enumerator_iter; result_pair() = default; @@ -1519,8 +1522,8 @@ template struct result_pair { } std::size_t index() const { return Index; } - const ValueOfRange &value() const { return *Iter; } - ValueOfRange &value() { return *Iter; } + const value_reference value() const { return *Iter; } + value_reference value() { return *Iter; } private: std::size_t Index = std::numeric_limits::max();