Debian Codegraph @

yo/coroutines/demo/corodir/iterator.imp

raw
1 template<typename T>
2 inline Iterator<T>::Iterator(Handle handle) noexcept
3 :
4 d_coHandle(handle)
5 {}
6
7
8 template<typename T>
9 Iterator<T> &Iterator<T>::operator++()
10 {
11 d_coHandle.resume();
12 if (d_coHandle.done())
13 {
14 d_coHandle.promise().rethrow_if_exception();
15 }
16
17 return *this;
18 }
19
20 template<typename T>
21 inline typename Promise<T>::Reference Iterator<T>::operator*() const noexcept
22 {
23 return d_coHandle.promise().value();
24 }
25
26 template<typename T>
27 inline typename Promise<T>::Value *Iterator<T>::operator->() const noexcept
28 {
29 return std::addressof(operator*());
30 }
31
32 // Need to provide post-increment operator to implement the 'Range' concept.
33 template<typename T>
34 inline void Iterator<T>::operator++(int)
35 {
36 operator++();
37 }
38
39 template<typename T>
40 inline bool operator==(Iterator<T> const &it, Sentinel) noexcept
41 {
42 return not it.d_coHandle or it.d_coHandle.done();
43 }
44
45 template<typename T>
46 inline bool operator!=(Iterator<T> const &it, Sentinel s) noexcept
47 {
48 return not (it == s);
49 }
50
51 template<typename T>
52 inline bool operator==(Sentinel s, Iterator<T> const &it) noexcept
53 {
54 return it == s;
55 }
56
57 template<typename T>
58 inline bool operator!=(Sentinel s, Iterator<T> const &it) noexcept
59 {
60 return it != s;
61 }
62