std::generator<Ref,V,Allocator>::iterator
来自cppreference.com
<tbody>
</tbody>
class /*iterator*/; |
(仅用于阐述*) | |
generator::begin 的返回类型。实现 indirectly_readable 和 input_iterator。
成员类型
| 成员类型 | 定义 |
value_type
|
std::generator::value
|
difference_type
|
std::ptrdiff_t |
数据成员
| 成员 | 说明 |
std::coroutine_handle<std::generator::promise_type> coroutine_
|
协程句柄 (仅用于阐述的成员对象*) |
成员函数
| 构造迭代器 (公开成员函数) | |
| 赋值给另一迭代器 (公开成员函数) | |
| 返回底层的值 (公开成员函数) | |
| 推进迭代器 (公开成员函数) |
std::generator::iterator::iterator
<tbody> </tbody> /*iterator*/( /*iterator*/&& other ) noexcept; |
(C++23 起) | |
以 std::exchange(other.coroutine_, {}); 初始化 coroutine_。
std::generator::iterator::operator=
<tbody> </tbody> /*iterator*/& operator=( /*iterator*/&& other ) noexcept; |
(C++23 起) | |
等价于 coroutine_ = std::exchange(other.coroutine_, {});。
返回:*this。
std::generator::iterator::operator*
<tbody> </tbody> reference operator*() const noexcept( std::is_nothrow_copy_constructible_v<reference> ); |
(C++23 起) | |
- 令
reference表示std::generator的底层类型。 - 令
x是某个生成器对象,其coroutine_在栈*x.active_中。 - 令
x.active_->top()指代具有承诺对象p的暂停的协程。
等价于 return static_cast<reference>(*p.value_);。
std::generator::iterator::operator++
<tbody> </tbody> constexpr /*iterator*/& operator++(); |
(1) | (C++23 起) |
constexpr void operator++( int ); |
(2) | (C++23 起) |
等价于
x.active_->top().resume()。 返回:
*this。2) 等价于
++*this;。
非成员函数
(C++23) |
将底层迭代器和哨位进行比较 (函数) |
operator==(std::generator::iterator)
<tbody> </tbody> friend bool operator==( const /*iterator*/& i, std::default_sentinel_t ); |
(C++23 起) | |
等价于 return i.coroutine_.done();。
!= 运算符从 operator== 运算符合成。
此函数对常规的无限定或有限定查找不可见,而只能在 std::generator::iterator 为实参的关联类时由实参依赖查找找到。
Example
| 本节未完成 原因:暂无示例 |