From: Mehdi Amini Date: Fri, 21 Jun 2019 05:43:08 +0000 (+0000) Subject: Use std::iterator_traits to infer result type of llvm::enumerate iterator wrapper X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1a1e51aaebf3b89f4589946cbb708700ba1fcb3;p=llvm 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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364007 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h index eb9dff3efed..de82f2bce7f 100644 --- a/include/llvm/ADT/STLExtras.h +++ b/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();