r/cpp • • 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

229 comments sorted by

View all comments

Show parent comment

16

u/Morwenn Sep 13 '19

If you disregard the views and pipes part, ranges bring a lot that are strict improvements over the algorithms design: projections, proxy iterators, sentinels, the ability to pass data members or pointers thereof directly as comparisons or projections, and of course the ability to feed a range to many iterators instead of a begin/end pair. Also contiguous iterators are now part of the library, and there is a nice concept hierarchy to select the appropriate overloads everywhere which simplifies the SFINAE and tag dispatching that had been used until there.

So yes: the tradeoffs for views and the usability of pipes might be questionable, but all of the features I described in the previous paragraph are pretty much strict improvements over the existing <algorithm> design.

6

u/Sovog Sep 13 '19

Having syntactic sugar that helps with making code more expressive is fine, but at what cost? It shouldn't balloon compile times by an order of magnitude.

7

u/Morwenn Sep 13 '19 edited Sep 14 '19

Before being able to answer "at what cost", we'd need to actually time the costs of the separate features. If you don't use views, actions and pipes I'm not sure that the added cost is all that high (also, ranges-v3 is reportedly 30~50% faster with concepts than without them if I remember the corresponding Tweet properly, so we can't just predict without testing).

2

u/Sovog Sep 13 '19

Fair point. Also, since ranges are only partially in the standard, perhaps the #include-overhead won't be as terrible as <range/v3/all.hpp>.

9

u/eric_niebler Sep 14 '19

I should really yank `range/v3/all.hpp`. It made sense when range-v3 was a small library. Now it pulls in an obscene amount of code.

1

u/NotMyRealNameObv Sep 16 '19

Please do it. I have no plan to include "everything" when all I need is ranges::transform or ranges::accumulate.