3 ms·
Yeah, but is this really better than explicitly managing a stack? Here is how I one could write in C: https://godbolt.org/z/P3ErP4T4d https://godbolt.org/z/P3E
by uecker 2y ago
Yeah, but is this really better than explicitly managing a stack?
Here is how I one could write in C: https://godbolt.org/z/P3ErP4T4d https://godbolt.org/z/P3ErP4T4d or possibly with the setup code moved into the helper function for convenience: https://godbolt.org/z/soz7W5z1G https://godbolt.org/z/soz7W5z1G
- injidup 2y agoSure you can do it any way but the OP was about adding language features for iteration of a specific data structure. Iteration in C++ is state machine based and coroutines give you a neat way to implicitly model them without having to manage the boiler plate yourself.
- uecker 2y agoYeah, but what I do not get is why you need all this. What problem does this solve? The C function that advances to the next tree node does exactly the same. And what is neat about it? It just seems a lot more complicated. Or in other words: A new language feature should make things simpler and not more complicated to express. But maybe I am just missing a realistic examples where it actually makes things simpler?