Skip to content
dmishin edited this page Sep 14, 2010 · 3 revisions

—Simple, lightweight, cross-platform, header-only C++ library for imitating generators

The “pseudo_generator” library imitates continuations and facilitates writing code in a generator style, just like in Python and some other languages.

It is “pseudo”, because it is not a real continuations, which are not supported by C++ in general.
Instead of capturing variables in closure, they are stored in the structure, and macros are used to save and restore the execution point.

Main properties of the pseudo-generator:

  1. It is cross-platform: the code is a standard C++, no compiler-dependent or OS-dependent extensions are used. Generator code should compile on every standard_compliant C++ compiler.
  2. Low overhead: call to the generator is the same as call to the regular method + executing an additional switch operator. In acse of complex generators, you probably can’t write by-hand code, that would be more effective.
  3. STL support: generators provide iterator adapter, which can be used to apply STL algorithms to the generator directly.

Code samples: Samples

How it works

Clone this wiki locally