| 57 | // input_iterator -- it doesn't inherit any superpowers NestedIterator may have. |
| 58 | template <typename NestedIter> |
| 59 | class UnwrappingIterator |
| 60 | : public std::iterator<std::input_iterator_tag, |
| 61 | decltype(std::declval<NestedIter>()->get())> { |
| 62 | private: |
| 63 | NestedIter iter_; |
| 64 | |
| 65 | public: |
| 66 | explicit UnwrappingIterator(NestedIter iter) : iter_(std::move(iter)) {} |
| 67 | |
| 68 | auto operator*() -> decltype(iter_->get()) { return iter_->get(); } |
| 69 | auto operator-> () -> decltype(iter_->get()) { return iter_->get(); } |
| 70 | UnwrappingIterator& operator++() { |
| 71 | ++iter_; |
| 72 | return *this; |
| 73 | } |
| 74 | UnwrappingIterator operator++(int) { |
| 75 | UnwrappingIterator temp(iter_); |
| 76 | operator++(); |
| 77 | return temp; |
| 78 | } |
| 79 | |
| 80 | friend bool operator==(const UnwrappingIterator& a, |
| 81 | const UnwrappingIterator& b) { |
| 82 | return a.iter_ == b.iter_; |
| 83 | } |
| 84 | |
| 85 | friend bool operator!=(const UnwrappingIterator& a, |
| 86 | const UnwrappingIterator& b) { |
| 87 | return !(a == b); |
| 88 | } |
| 89 | }; |
| 90 | |
| 91 | template <typename NestedIter> |
| 92 | UnwrappingIterator<NestedIter> MakeUnwrappingIterator(NestedIter iter) { |