@@ -93,7 +93,7 @@ namespace cppcoro
93
93
94
94
using iterator_category = std::input_iterator_tag;
95
95
// What type should we use for counting elements of a potentially infinite sequence?
96
- using difference_type = std::size_t ;
96
+ using difference_type = std::ptrdiff_t ;
97
97
using value_type = typename generator_promise<T>::value_type;
98
98
using reference = typename generator_promise<T>::reference_type;
99
99
using pointer = typename generator_promise<T>::pointer_type;
@@ -107,25 +107,25 @@ namespace cppcoro
107
107
: m_coroutine(coroutine)
108
108
{}
109
109
110
- bool operator ==(const generator_iterator& other) const noexcept
110
+ friend bool operator ==(const generator_iterator& it, generator_sentinel) noexcept
111
111
{
112
- return m_coroutine == other .m_coroutine ;
112
+ return !it. m_coroutine || it .m_coroutine . done () ;
113
113
}
114
114
115
- bool operator ==(generator_sentinel) const noexcept
116
- {
117
- return !m_coroutine || m_coroutine.done ();
118
- }
119
-
120
- bool operator !=(const generator_iterator& other) const noexcept
115
+ friend bool operator !=(const generator_iterator& it, generator_sentinel) noexcept
121
116
{
122
117
return !(*this == other);
123
118
}
124
119
125
- bool operator !=(generator_sentinel other) const noexcept
126
- {
127
- return !operator ==(other);
128
- }
120
+ friend bool operator ==(generator_sentinel s, const generator_iterator& it) noexcept
121
+ {
122
+ return (it == s);
123
+ }
124
+
125
+ friend bool operator !=(generator_sentinel s, const generator_iterator& it) noexcept
126
+ {
127
+ return it != s;
128
+ }
129
129
130
130
generator_iterator& operator ++()
131
131
{
@@ -201,11 +201,11 @@ namespace cppcoro
201
201
m_coroutine.resume ();
202
202
if (m_coroutine.done ())
203
203
{
204
- m_coroutine.promise ().rethrow_if_exception ();
204
+ m_coroutine.promise ().rethrow_if_exception ();
205
205
}
206
206
}
207
207
208
- return iterator{ m_coroutine };
208
+ return iterator{ m_coroutine };
209
209
}
210
210
211
211
detail::generator_sentinel end () noexcept
0 commit comments