Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
generator_example.cc File Reference

Aleph::Generator<T>: lazy sequences with C++20 coroutines. More...

#include <cctype>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include <ah-generator.H>
#include <print_rule.H>
Include dependency graph for generator_example.cc:

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

Aleph::Generator<T>: lazy sequences with C++20 coroutines.

Overview

Aleph::Generator<T> (see ah-generator.H) turns a function that co_yields values into a lazy, single-pass sequence you can drive with an ordinary range-for. This example walks through the three reasons to reach for it:

  • Laziness: sequences that are infinite, or merely huge, can be expressed directly — nothing is computed until the consumer asks for the next value, and break stops production outright.
  • Exception propagation: a coroutine body can validate as it goes and throw partway through; the exception surfaces at the point the consumer resumed it, exactly like a hand-written iterator would.
  • Composability: a generator function can itself consume another generator with a plain range-for and re-co_yield, chaining lazy stages the way map/filter chain in ahFunctional.H.
Author
Leandro Rabindranath Leon

Definition in file generator_example.cc.

Function Documentation

◆ main()

int main ( void  )