4 ms·
What's the difference between this and something like python-esque generators which also appear to be lazy and have a much saner syntax? Doesn't C++ plan to sup
by krackers 8y ago
What's the difference between this and something like python-esque generators which also appear to be lazy and have a much saner syntax? Doesn't C++ plan to support coroutines which should provide a similar way to lazily evaluate lists?
Also the example has a lot of boilerplate code that reminds me of template metaprogramming hell. Is this something that's expected to be wrapped up nicely by Boost & co. for end users?
- mikeloomis 8y agoA c++20 range is just a bounded container. instead of having to write, `(container.begin(), container.end())` for any function that uses iterators to bound itself, you just write `(container)` and it knows its a range. The range function in python is similar only in name, the c++20 range concept is not a generator. 2. There is a coroutine feature branch, I believe developed by Gor Nishanov, https://github.com/GorNishanov https://github.com/GorNishanov. Also not related to c++20 ranges. 3. Eric Niebler used a single templated function. This is not anywhere close to template metaprogramming hell, and I think you should look into templates as once you learn about them they become way less intimidating. Also has nothing to do with c++20 ranges.
- amelius 8y agoI have yet to see a non-managed systems programming language which supports coroutines properly. Rust supports async/await, but it's not the same thing, as this comment illustrates: https://news.ycombinator.com/item?id=15121199 https://news.ycombinator.com/item?id=15121199
- mikeloomis 8y agoIt'll be after 20 for sure, we're still waiting for the executor TS for async networking to be able to come in.
- Sharlin 8y agoThe "for_each" (aka flatmap, or bind, or =<<), "maybe_view", and "yield_if" are basically a DSL for writing (admittedly ugly) lazy list comprehensions (generator expressions in Python or for comprehensions in Scala) in C++ without special language support for them. You're not supposed to have to implement these sorts of building blocks yourself, but they're not voted into the standard either at this point.
- mattnewport 8y agoUnlike Python, this compiles to pretty optimally efficient code.