[coro.generator.iterator]

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

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

### 25.8.6 Class generator​::​*iterator* [coro.generator.iterator]

namespace std {template<class Ref, class Val, class Allocator>class generator<Ref, Val, Allocator>::*iterator* {public:using value_type = *value*; using difference_type = ptrdiff_t; *iterator*(*iterator*&& other) noexcept; *iterator*& operator=(*iterator*&& other) noexcept; *reference* operator*() const noexcept(is_nothrow_copy_constructible_v<*reference*>); *iterator*& operator++(); void operator++(int); friend bool operator==(const *iterator*& i, default_sentinel_t); private: coroutine_handle<promise_type> *coroutine_*; // *exposition only*};}

[ð](#lib:generator::iterator,constructor)

`iterator(iterator&& other) noexcept;
`

[1](#1)

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

*Effects*: Initializes *coroutine_* with exchange(other.*coroutine_*, {})[.](#1.sentence-1)

[ð](#lib:operator=,generator::iterator)

`iterator& operator=(iterator&& other) noexcept;
`

[2](#2)

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

*Effects*: Equivalent to*coroutine_* = exchange(other.*coroutine_*, {})[.](#2.sentence-1)

[3](#3)

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

*Returns*: *this[.](#3.sentence-1)

[ð](#lib:operator*,generator::iterator)

`reference operator*() const noexcept(is_nothrow_copy_constructible_v<reference>);
`

[4](#4)

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

*Preconditions*: For some generator object x,*coroutine_* is in *x.*active_* andx.*active_*->top() refers to
a suspended coroutine with promise object p[.](#4.sentence-1)

[5](#5)

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

*Effects*: Equivalent to:return static_cast<*reference*>(*p.*value_*);

[ð](#lib:operator++,generator::iterator)

`iterator& operator++();
`

[6](#6)

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

*Preconditions*: For some generator object x,*coroutine_* is in *x.*active_*[.](#6.sentence-1)

[7](#7)

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

*Effects*: Equivalent to x.*active_*->top().resume()[.](#7.sentence-1)

[8](#8)

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

*Returns*: *this[.](#8.sentence-1)

[ð](#lib:operator++,generator::iterator_)

`void operator++(int);
`

[9](#9)

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

*Effects*: Equivalent to ++*this[.](#9.sentence-1)

[ð](#lib:operator==,generator::iterator)

`friend bool operator==(const iterator& i, default_sentinel_t);
`

[10](#10)

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

*Effects*: Equivalent to: return i.*coroutine_*.done();
