dmishin / pseudo_generator Goto Github PK
View Code? Open in Web Editor NEWA simple header-only C++ library, that imitates Python's generators (i.e. continuations)
A simple header-only C++ library, that imitates Python's generators (i.e. continuations)
Generators (continuations) for C++ Some languages, partcaularly, Python, support a very useful feature called "generators". It is a special case of the thing, known as "continuations". Here is a sample Python code for those, who by some reason do now know about them: [pyton] def primes(): yield 2 x = 3 while True: for d in range( [/python] Is there any way to implement this in C++? Well, not really. Support for continuations require that execution state can be saved and restored arbitratily. C++ model of execution does not allows this. BOOST offers generators library, based on a trick with threads: generator code is effectively runned in the separate thread, which eliminates the nececerity for saving execution state. This offers excellent "real" genrators, just like in Python, but some may think about such approach as about overkill. What I want is a simple, standart-compliant, low-overhead library, that can facilitate writing code in generator style. ANd, here it is. That's how you can implement the same genreator with this library: [C++] struct my_generator: public pseudo_generator<int> { int,; int operator()(); }; int my_generator::operator()() { BEGIN_GENERATOR2( s1, s2 ); for END_GENERATOR; return -1; //dummy return; }; [/C++] SOmewhat more dirty, than Python, but significantly more clear than onriginal C++. { How it works }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.