return *this;
}
- bool operator==(const Enumerator& rhs) {
+ template <typename OtherIterator>
+ bool operator==(const Enumerator<OtherIterator>& rhs) {
return it_ == rhs.it_;
}
- bool operator!=(const Enumerator& rhs) {
+ template <typename OtherIterator>
+ bool operator!=(const Enumerator<OtherIterator>& rhs) {
return !(*this == rhs);
}
private:
+ template <typename OtherIterator>
+ friend class Enumerator;
+
Iterator it_;
size_t idx_ = 0;
};
template <class Range>
class RangeEnumerator {
Range r_;
- using Iterator = decltype(r_.begin());
+ using BeginIteratorType = decltype(std::declval<Range>().begin());
+ using EndIteratorType = decltype(std::declval<Range>().end());
public:
explicit RangeEnumerator(Range&& r) : r_(std::forward<Range>(r)) {}
- Enumerator<Iterator> begin() {
- return Enumerator<Iterator>(r_.begin());
+ Enumerator<BeginIteratorType> begin() {
+ return Enumerator<BeginIteratorType>(r_.begin());
}
- Enumerator<Iterator> end() {
- return Enumerator<Iterator>(r_.end());
+ Enumerator<EndIteratorType> end() {
+ return Enumerator<EndIteratorType>(r_.end());
}
};