promise_type/final_suspend
"cpp/coroutine/generator/promise type/final suspend")  
[ generator::promise_type::yield_value
](/w/cpp/coroutine/generator/promise_type/yield_value
"cpp/coroutine/generator/promise type/yield value")  
[ generator::promise_type::return_void
](/w/cpp/coroutine/generator/promise_type/return_void
"cpp/coroutine/generator/promise type/return void")  
[ generator::promise_type::unhandled_exception
](/w/cpp/coroutine/generator/promise_type/unhandled_exception
"cpp/coroutine/generator/promise type/unhandled exception")  
[ generator::promise_type::operator new
](/w/cpp/coroutine/generator/promise_type/operator_new
"cpp/coroutine/generator/promise type/operator new")  
[ generator::promise_type::operator delete
](/w/cpp/coroutine/generator/promise_type/operator_delete
"cpp/coroutine/generator/promise type/operator delete")  
[ _Iterator_ ](/w/cpp/coroutine/generator/iterator
"cpp/coroutine/generator/iterator")  
[ generator:: _iterator_ :: _iterator_
](/w/cpp/coroutine/generator/iterator#constructor
"cpp/coroutine/generator/iterator")  
[ generator:: _iterator_ ::operator=
](/w/cpp/coroutine/generator/iterator#assignment
"cpp/coroutine/generator/iterator")  
[ generator:: _iterator_ ::operator*
](/w/cpp/coroutine/generator/iterator#dereference
"cpp/coroutine/generator/iterator")  
[ generator:: _iterator_ ::operator++  
generator:: _iterator_ ::operator++  (int)
](/w/cpp/coroutine/generator/iterator#increment
"cpp/coroutine/generator/iterator")  
[ operator==  (generator:: _iterator_ , std::default_sentinel_t)
](/w/cpp/coroutine/generator/iterator#compare
"cpp/coroutine/generator/iterator")  
  
[ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/coroutine/generator/navbar_content&action=edit)

Defined in header ` [ <generator> ](/w/cpp/header/generator "cpp/header/generator") ` |  |   
---|---|---  
template  <  
class  Ref,  
class  V  =  void  ,  
class  Allocator  =  void  >  
class  generator  
:  public  [ ranges::  view_interface  ](http://en.cppreference.com/w/cpp/ranges/view_interface) < generator  < Ref, V, Allocator  >> |  (1)  |  (since C++23)   
namespace  pmr  {  
template  < class  Ref,  class  V  =  void  >  
using  generator  =  
std  ::  generator  < Ref, V, [ std::  pmr  ::  polymorphic_allocator
](http://en.cppreference.com/w/cpp/memory/polymorphic_allocator) <>> ;  
}  |  (2)  |  (since C++23)   
|  |   
  
1)  The class template ` std::generator ` presents a [ ` view `
](/w/cpp/ranges/view "cpp/ranges/view") of the elements yielded by the
evaluation of a [ coroutine ](/w/cpp/language/coroutines
"cpp/language/coroutines") .

2)  Convenience alias template for the ` generator ` using the [ polymorphic
allocator ](/w/cpp/memory/polymorphic_allocator "cpp/memory/polymorphic
allocator") .

A ` std::generator ` generates a sequence of elements by repeatedly resuming
the coroutine from which it was returned. Each time a  co_yield  statement is
evaluated, the coroutine produces one element of the sequence. When the
co_yield  statement is of the form  co_yield ranges  ::  elements_of  (  rng
)  , each element of the [ ` range ` ](/w/cpp/ranges/range "cpp/ranges/range")
rng  is successively produced as an element of the sequence.

` std::generator ` models [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view")
and [ ` input_range ` ](/w/cpp/ranges/input_range "cpp/ranges/input range") .

The behavior of a program that adds a specialization for ` std::generator ` is
undefined.

##  Contents

  * 1  Template parameters 
  * 2  Member types 
  * 3  Member objects 
  * 4  Member functions 
    * 4.1  Inherited from  std::ranges::view_interface 
  * 5  Nested classes 
  * 6  Notes 
  * 7  Example 
  * 8  References 
  * 9  See also 

  
---  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/coroutine/generator&action=edit&section=1 "Edit
section: Template parameters") ]  Template parameters

Ref  |  \-  |  the reference type (  ranges::range_reference_t  ) of the generator. If ` V ` is