r/cpp • • Jun 26 '26

projections for stl data structures

using projection in ranges::sort has removed the need write a compartor function or a lambda and is much easier to implement in my opinion

there should exists a similar feature for say sets or priority queues

would be wonnderful if I could just write

priority_queue<Student, Student::marks> for example

21 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/kal_at_kalx_net Jul 05 '26

I will go further: using projections as arguments to `std::ranges` functions was a fundamental design mistake. The Linq approach builds an AST that can provide more information to optimizing compilers. This thread is just another artifact of that original design mistake.

Stepanov thinks `std::ranges` is too complicated. He is right.

2

u/_Noreturn Jul 05 '26

I do agree, they are complex in every way from using concepts, bloated interfaces and bad debugability and bad compile times. it is laughable that they succeed in sucking in every way.

It is just that the committee never uses the stl before shoving it down our throats so we get garbage.