Create a Generator as Iterators

Learn to create a generator as an iterator.

A generator is an iterator that generates its own sequence of values. It does not use a container. It creates values on the fly, returning one at a time as needed. A C++ generator stands on its own; it does not need to wrap around another object.

In this recipe, we'll build a generator for a Fibonacci sequenceThe Fibonacci sequence is a series of numbers where each number is the sum of the two preceding numbers, starting with 1, 1.. This is a sequence where each number is the sum of the previous two numbers in the sequence, starting with 00 and 11:

Get hands-on with 1400+ tech skills courses.