Use std::iterator_traits to infer result type of llvm::enumerate iterator wrapper

Update the llvm::enumerate helper class result_pair<R> to use the 'iterator_traits<R>::reference'
type as the result of 'value()' instead 'ValueOfRange<R> &'. 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 <riverriddle@google.com>

Differential Revision: https://reviews.llvm.org/D63632

llvm-svn: 364007
This commit is contained in:
Mehdi Amini 2019-06-21 05:43:08 +00:00
parent dc8de6037c
commit fc9aa33def
1 changed files with 5 additions and 2 deletions

View File

@ -1506,6 +1506,9 @@ namespace detail {
template <typename R> class enumerator_iter;
template <typename R> struct result_pair {
using value_reference =
typename std::iterator_traits<IterOfRange<R>>::reference;
friend class enumerator_iter<R>;
result_pair() = default;
@ -1519,8 +1522,8 @@ template <typename R> struct result_pair {
}
std::size_t index() const { return Index; }
const ValueOfRange<R> &value() const { return *Iter; }
ValueOfRange<R> &value() { return *Iter; }
const value_reference value() const { return *Iter; }
value_reference value() { return *Iter; }
private:
std::size_t Index = std::numeric_limits<std::size_t>::max();