// std::generator<X>,co_yield出来的数据类型是X&&std::generator<X>always_ref_example(){co_yieldX{1};// 右值,不会发生拷贝{Xx{2};co_yieldx;// 左值,会发生拷贝assert(x.id==2);}{constXx{3};co_yieldx;// const X&,也会发生拷贝assert(x.id==3);}{Xx{4};co_yieldstd::move(x)...
std::generator<char>print_l_one(){co_yield'l';}std::generator<int>print_l_two(){co_yield'l';}template<typenameT>structCharO{// 具体实现附后Tvalue{static_cast<T>('o')};structIterator{...T*p{};T&&operator*()const{assert(!p);returnstd::move(*p);}...};...};std::generator<...
范围库 std::generator /*iterator*/begin(); (C++23 起) 将coroutine_推入栈*active_中,然后对coroutine_.resume()求值。 在调用begin()之前,coroutine_必须指代一个在其初始暂停点暂停的协程。 返回值 迭代器,其成员coroutine_与coroutine_指代同一协程。
std::generator is a C++23 feature that enables you to write concise, straightforward functions that generate sequences of values on-demand without manually managing state. It builds upon C++20’s coroutines, providing some standard library support for this powerful, but complex, language feature. ...
std::generator<uint64_t>factorize(uint64_tm){if(is_prime(m)){co_yield m;}elseif(m>1){autog=proper_divisor(m);co_yield std::ranges::elements_of(factorize(g));co_yield std::ranges::elements_of(factorize(m/g));}}for(intp:factorize(m)){...} ...
std::swap(coroutine_, other.coroutine_); std::swap(active_, other.active_); 参数other - 要被移动的生成器对象 返回值*this 复杂度本节未完成 注解来自other 的迭代器不会失效 – 他们现在是 *this 中的迭代器。 这个赋值运算符技术上是一个复制赋值运算符,虽然 std::generator 仅可移动赋值。 示例...
中文 English Home > Product > Default Product STD GeneratorPhone Share Top
std::generator<Ref,V,Allocator>::iterator From cppreference.com <cpp |coroutine |generator The return type ofgenerator::begin. Modelsindirectly_readableandinput_iterator. Member types Member typeDefinition value_typestd::generator::value ...
std::generator Defined in header<generator> template< classRef, classV=void, classAllocator=void> classgenerator :publicranges::view_interface<generator<Ref, V, Allocator>> (1)(since C++23) namespacepmr{ template<classRef,classV=void>
explicit sync_generator(std::generator<T>&& gen); sync_generator(const sync_generator<T>& other) = delete; sync_generator(sync_generator<T>&& other) = default; sync_generator& operator=(const sync_generator<T>& other) = delete; sync_generator& operator=(sync_generator<T>&& other) = ...