-
Notifications
You must be signed in to change notification settings - Fork 0
Home
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:
- 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.
- 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.
- STL support: generators provide iterator adapter, which can be used to apply STL algorithms to the generator directly.
Code samples: Samples