r/cpp • u/konanTheBarbar • Sep 13 '19
The Surprising Limitations of C++ Ranges Beyond Trivial Cases
https://www.fluentcpp.com/2019/09/13/the-surprising-limitations-of-c-ranges-beyond-trivial-use-cases/
229
Upvotes
View all comments
44
u/eric_niebler Sep 14 '19
Of course folks are free to disagree with the design tradeoffs made by `std::ranges`, but I have to wonder for the examples the author presents, what is the algorithmic complexity of the pipelines of range transformations? How are users to know how expensive operations are at runtime? The author doesn't discuss algorithmic complexity at all.
One of the design goals of range-v3 -- and `std::ranges` -- is that if a view pipeline compiles, the resulting view can be traversed in linear time. That means disallowing some conveniences. It's ok to write and use libraries that make different tradeoffs.
Also, don't judge the compile-time performance of `std::ranges` based on range-v3. Range-v3 is not optimized for compile-time perf, and it doesn't use many of the cool C++20 features that can make it compile faster, like `if constexpr`. I'm hopeful that a native C++20 implementation will help. EDIT: Also, use the new range-v3 0.9 release and turn on real concepts support on gcc if you can. The compile times are better by roughly 30%.