[coro.generator.class]

# 25 Ranges library [[ranges]](./#ranges)

## 25.8 Range generators [[coro.generator]](coro.generator#class)

### 25.8.3 Class template generator [coro.generator.class]

namespace std {template<class Ref, class Val = void, class Allocator = void>class [generator](#lib:generator "25.8.3 Class template generator [coro.generator.class]") : public ranges::view_interface<generator<Ref, Val, Allocator>> {private:using *value* = conditional_t<is_void_v<Val>, remove_cvref_t<Ref>, Val>; // *exposition only*using *reference* = conditional_t<is_void_v<Val>, Ref&&, Ref>; // *exposition only*// [[coro.generator.iterator]](coro.generator.iterator "25.8.6 Class generator​::​iterator"), class generator​::​*iterator*class *iterator*; // *exposition only*public:using yielded = conditional_t<is_reference_v<*reference*>, *reference*, const *reference*&>; // [[coro.generator.promise]](coro.generator.promise "25.8.5 Class generator​::​promise_­type"), class generator​::​promise_typeclass 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*};}

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L18121)

*Mandates*: 

- [(1.1)](#1.1)

  If Allocator is not void,allocator_traits<Allocator>​::​pointer is a pointer type[.](#1.1.sentence-1)

- [(1.2)](#1.2)

  *value* is a cv-unqualified object type[.](#1.2.sentence-1)

- [(1.3)](#1.3)

  *reference* is either a reference type, or
a cv-unqualified object type that models [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]")[.](#1.3.sentence-1)

- [(1.4)](#1.4)

  Let RRef denote remove_reference_t<*reference*>&& if *reference* is a reference type,
and *reference* otherwise[.](#1.4.sentence-1)
  Each of:
  * [(1.4.1)](#1.4.1)

[common_reference_with](concept.commonref#concept:common_reference_with "18.4.5 Concept common_­reference_­with [concept.commonref]")<*reference*&&, *value*&>,

  * [(1.4.2)](#1.4.2)

[common_reference_with](concept.commonref#concept:common_reference_with "18.4.5 Concept common_­reference_­with [concept.commonref]")<*reference*&&, RRef&&>, and

  * [(1.4.3)](#1.4.3)

[common_reference_with](concept.commonref#concept:common_reference_with "18.4.5 Concept common_­reference_­with [concept.commonref]")<RRef&&, const *value*&>

is modeled[.](#1.4.sentence-2)
  [*Note [1](#note-1)*:
  These requirements ensure the exposition-only *iterator* type
can model [indirectly_readable](iterator.concept.readable#concept:indirectly_readable "24.3.4.2 Concept indirectly_­readable [iterator.concept.readable]") and thus [input_iterator](iterator.concept.input#concept:input_iterator "24.3.4.9 Concept input_­iterator [iterator.concept.input]")[.](#1.4.sentence-3)
 â *end note*]

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L18149)

If Allocator is not void,
it shall meet the *Cpp17Allocator* requirements[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L18153)

Specializations of generator model[view](range.view#concept:view "25.4.5 Views [range.view]") and [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]")[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L18157)

The behavior of a program that adds a specialization
for generator is undefined[.](#4.sentence-1)
