
On Jan 6, 2011, at 7:40 AM, Mathias Gaunard wrote:
On 05/01/2011 15:38, Howard Hinnant wrote:
I looked at:
http://en.wikipedia.org/wiki/Coroutine
and was unsuccessful in translating that idea to this application. Perhaps you could elaborate?
Look at the first example on that page, produce/consume: your for_each-style algorithm is similar to the 'produce' coroutine, and iteration of ranges is similar to the 'consume' coroutine.
Coroutines are typically implemented in C++ by storing the current context somewhere (registers, stack, PC), and switching to another context. This can be done in assembler or using OS-specific routines.
It's similar to threads, except there is no scheduler, typically no kernel, and no concurrency involved.
There is a Boost.Coroutine library somewhere, if you want to try it. I wrote some code with it that converts a for_each-style mechanism into a classic pair of iterators, if you're interested.
Thanks for the elaboration. I'm currently lacking the time and motivation to pursue this transformation. However I would eagerly review the results if someone were to take up that mantle and run with it. -Howard