[PATCH] D63632: Update the llvm::enumerate utility class result_pair to use the 'iterator_traits<R>::reference' instead of 'ValueOfIter<R> &'.
River Riddle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 20 16:52:57 PDT 2019
rriddle created this revision.
rriddle added reviewers: jpienaar, mehdi_amini.
Herald added subscribers: llvm-commits, kristina, dexonsmith.
Herald added a project: LLVM.
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.
Repository:
rL LLVM
https://reviews.llvm.org/D63632
Files:
llvm/include/llvm/ADT/STLExtras.h
Index: llvm/include/llvm/ADT/STLExtras.h
===================================================================
--- llvm/include/llvm/ADT/STLExtras.h
+++ llvm/include/llvm/ADT/STLExtras.h
@@ -1506,6 +1506,10 @@
template <typename R> class enumerator_iter;
template <typename R> struct result_pair {
+ using value_reference =
+ typename std::iterator_traits<IterOfRange<R>>::reference;
+
+public:
friend class enumerator_iter<R>;
result_pair() = default;
@@ -1519,8 +1523,8 @@
}
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();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63632.205923.patch
Type: text/x-patch
Size: 827 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190620/ebdc3203/attachment.bin>
More information about the llvm-commits
mailing list