Generators are a staple feature of functional programming languages. They are usually implemented through a combination of lambdas and lazy evaluation, allowing code like the following:
// pseudocode
vector<int> values = generate(1, maxInt, [](){/*generatorCode*/}).pick(100)
The generator function usually generates an infinite number of values, but because it is lazy evaluated, the 100 values materialize only when pick is called.
C++ doesn't yet have standard support for lazy evaluation and data generators, so we'll have to implement our own generator. It's worth noting that C++ 20 has adopted the inclusion of the awesome ranges library in the standard, which enables both these features. For the goals of this chapter, we'll stick to the standard available today, but you'll find the basic usage of ranges library in the final chapters of...