std::generator<Ref,V,Allocator>::iterator

来自cppreference.com
< cpp‎ | coroutine‎ | generator
 
 
 
协程支持
协程特征
协程句柄
无操作协程
平凡可等待体
范围生成器
(C++23)
 
范围库
范围适配器
 
 
class /*iterator*/;
(仅用于阐述*)

generator::begin 的返回类型。实现 indirectly_readableinput_iterator

目录

[编辑] 成员类型

成员类型 定义
value_type std::generator::value
difference_type std::ptrdiff_t

[编辑] 数据成员

成员 说明
std::coroutine_handle<std::generator::promise_type> coroutine_ 协程句柄
(仅用于阐述的成员对象*)

[编辑] 成员函数

构造迭代器
(公开成员函数)
赋值给另一迭代器
(公开成员函数)
返回底层的值
(公开成员函数)
推进迭代器
(公开成员函数)

std::generator::iterator::iterator

/*iterator*/( /*iterator*/&& other ) noexcept;
(C++23 起)

std::exchange(other.coroutine_, {}); 初始化 coroutine_

std::generator::iterator::operator=

/*iterator*/& operator=( /*iterator*/&& other ) noexcept;
(C++23 起)

等价于 coroutine_ = std::exchange(other.coroutine_, {});

返回:*this

std::generator::iterator::operator*

reference operator*() const
    noexcept( std::is_nothrow_copy_constructible_v<reference> );
(C++23 起)
  1. reference 表示 std::generator 的底层类型。
  2. x 是某个生成器对象,其 coroutine_ 在栈 *x.active_ 中。
  3. x.active_->top() 指代具有承诺对象 p 的暂停的协程。

等价于 return static_cast<reference>(*p.value_);

std::generator::iterator::operator++

constexpr /*iterator*/& operator++();
(1) (C++23 起)
constexpr void operator++( int );
(2) (C++23 起)
1)x 是某个生成器对象,其 coroutine_ 在栈 *x.active_ 中。
等价于 x.active_->top().resume()
返回:*this
2) 等价于 ++*this;

[编辑] 非成员函数

将底层迭代器和哨位进行比较
(函数)

operator==(std::generator::iterator)

friend bool operator==( const /*iterator*/& i, std::default_sentinel_t );
(C++23 起)

等价于 return i.coroutine_.done();

!= 运算符从 operator== 运算符合成

此函数对常规的无限定有限定查找不可见,而只能在 std::generator::iterator 为实参的关联类时由实参依赖查找找到。

[编辑] Example