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