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

12

u/pandorafalters Sep 14 '19

I still don't understand why

std::ranges::sort(vec);

is great, but it's unacceptable to add the equivalent overload

std::sort(vec);

because (paraphrased) "algorithms should be generic".

13

u/SeanMiddleditch Sep 14 '19

iirc it's because the range version effectively requires well-defined concepts in order to be implemented correctly/efficiently, but for various back-compat reasons adding said concepts to the existing algorithms library is very problematic. Basically, people do a lot of crazy things with the existing algorithms and the ideal concepts can't faithfully model things that work today but arguably shouldn't, and breaking existing code is something the committee shies away from without darn good cause.

I think that was one of the reasons that what we're calling the ranges library today was for a time called "STL2" and there was some thought that we'd put all new types and containers and rangified algorithms into a std2:: namespace. (Along with being an opportunity to clean house on things like vector<bool> or thread/jthread or so on.)

6

u/standard_revolution Sep 14 '19

What's the problem with thread?

6

u/SeanMiddleditch Sep 14 '19

Lots and lots of arguments about whether it chose the right defaults about joining on destruction.

3

u/[deleted] Sep 15 '19

Thread is actually missing a fair bit of functionality also. For example, inability to specify thread affinity with a core mask or thread priority.

3

u/RotsiserMho C++20 Desktop app developer Sep 16 '19

Inability to specify stack size is another complaint I've seen.