[ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/header/navbar_content&action=edit)

|

##  Contents

  * 1  Classes 
  * 2  Synopsis 
    * 2.1  Class template  std::  generator 
    * 2.2  Class  std::generator::promise_type 
    * 2.3  Class  std::generator::iterator 
  * 3  References 

  
---  
  
###  Classes  
  
[ generator  ](/w/cpp/coroutine/generator "cpp/coroutine/generator") (C++23)  |  A [ ` view ` ](/w/cpp/ranges/view "cpp/ranges/view") that represents synchronous [ coroutine ](/w/cpp/language/coroutines "cpp/language/coroutines") generator   
(class template)  [ [edit]
](https://en.cppreference.com/mwiki/index.php?title=Template:cpp/ranges/dsc_generator&action=edit)  
  
###  [ [ edit
](/mwiki/index.php?title=cpp/header/generator&action=edit&section=1 "Edit
section: Synopsis") ]  Synopsis

    
    
    namespace std {
      // class template generator
      template<class Ref, class V = void, class Allocator = void>
      class generator;
     
      namespace pmr {
        template<class Ref, class V = void>
        using generator = [std::generator](http://en.cppreference.com/w/cpp/coroutine/generator)<Ref, V, polymorphic_allocator<>>;
      }
    }

####  [ [ edit
](/mwiki/index.php?title=Template:cpp/synopsis/generator&action=edit&section=T-1
"Template:cpp/synopsis/generator") ]  Class template  [ std::  generator
](http://en.cppreference.com/w/cpp/coroutine/generator)

    
    
    namespace std {
      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>> {
      private:
        using value = conditional_t<is_void_v<V>, 
                                    remove_cvref_t< Ref >, V>;          // exposition only
        using reference = conditional_t<is_void_v<V>, Ref&&, Ref>;      // exposition only
     
        // class generator::iterator
        class iterator;                                                 // exposition only
     
      public:
        using yielded =
          conditional_t<is_reference_v<reference>, reference, const reference&>;
     
        // class generator::promise_type
        class promise_type;
     
        generator(const generator&) = delete;
        generator(generator&& other) noexcept;
     
        ~generator();
     
        generator& operator=(generator other) noexcept;
     
        iterator begin();
        default_sentinel_t end() const noexcept;
     
      private:
        coroutine_handle<promise_type> coroutine_ = nullptr;  // exposition only
        unique_ptr<stack<coroutine_handle<>>> active_;        // exposition only
      };
    }

####  [ [ edit
](/mwiki/index.php?title=Template:cpp/synopsis/generator&action=edit&section=T-2
"Template:cpp/synopsis/generator") ]  Class  std::generator::promise_type

    
    
    namespace std {
      template<class Ref, class V, class Allocator>
      class generator<Ref, V, Allocator>::promise_type {
      public:
        generator get_return_object() noexcept;
     
        suspend_always initial_suspend() const noexcept { return {}; }
        auto final_suspend() noexcept;
     
        suspend_always yield_value(yielded val) noexcept;
     
        auto yield_value(const remove_reference_t<yielded>& lval)
          requires is_rvalue_reference_v<yielded> &&
            constructible_from<remove_cvref_t<yielded>, const remove_reference_t<yielded>&>;
     
        template<class R2, class V2, class Alloc2, class Unused>
          requires same_as<typename generator<R2, V2, Alloc2>::yielded, yielded>
          auto yield_value(ranges::elements_of<generator<R2, V2, Alloc2>&&,
                           Unused> g) noexcept;
     
        template<[ranges::input_range](http://en.cppreference.com/w/cpp/ranges/input_range) R, class Alloc>
          requires convertible_to<[ranges::range_reference_t](http://en.cppreference.com/w/cpp/ranges/