3 ms·
The generator pattern is really not that fundamental a language construct, and, in general, is quite straightforward to implement in languages with powerful eno
by tathougies 10y ago
The generator pattern is really not that fundamental a language construct, and, in general, is quite straightforward to implement in languages with powerful enough abstractions. C++ is one such language: http://www.boost.org/doc/libs/1_62_0/libs/coroutine/doc/html/coroutine/coroutine/asymmetric.html http://www.boost.org/doc/libs/1_62_0/libs/coroutine/doc/html...
- gpderetta 10y agoI wouldn't call it straightforward, boost.coroutine requires custom assembler for its implementation. Then again, stackfull coroutines are significantly more powerful than generators available in most other programming languages (notable recent exceptions are Go and Lua). Boost.asio provides stackless generators [1] implemented purely in C++, by (ab)using the preprocessor and the switch statement. [1] http://www.boost.org/doc/libs/1_62_0/doc/html/boost_asio/overview/core/coroutine.html http://www.boost.org/doc/libs/1_62_0/doc/html/boost_asio/ove...