Skip to content

Commit fc9aa33

Browse files
committed
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 <[email protected]> Differential Revision: https://reviews.llvm.org/D63632 llvm-svn: 364007
1 parent dc8de60 commit fc9aa33

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,9 @@ namespace detail {
15061506
template <typename R> class enumerator_iter;
15071507

15081508
template <typename R> struct result_pair {
1509+
using value_reference =
1510+
typename std::iterator_traits<IterOfRange<R>>::reference;
1511+
15091512
friend class enumerator_iter<R>;
15101513

15111514
result_pair() = default;
@@ -1519,8 +1522,8 @@ template <typename R> struct result_pair {
15191522
}
15201523

15211524
std::size_t index() const { return Index; }
1522-
const ValueOfRange<R> &value() const { return *Iter; }
1523-
ValueOfRange<R> &value() { return *Iter; }
1525+
const value_reference value() const { return *Iter; }
1526+
value_reference value() { return *Iter; }
15241527

15251528
private:
15261529
std::size_t Index = std::numeric_limits<std::size_t>::max();

0 commit comments

Comments
 (0)