for(const auto& item : dummy_list) { ... }
It was fucking ugly and verbose use iterators for something so basic and simple.
for(const auto& item : dummy_list) { ... }
It was fucking ugly and verbose use iterators for something so basic and simple.
std::sort(my_container.begin(), my_container.end());
I mean, yes, in 0.1% of all cases I would want to sort something that is not an entire container, and for that it's great that this exists. But for the 99.9%, why isn't there an overload that would allow me to do: std::sort(my_container); for (int i : ints | std::views::filter(even) | std::views::transform(square)) {
std::cout << i << ' ';
}
notice the `for (int i:ints)` and the pipes filters.EDIT: more specifically, you can use sort on a range now (source : https://cppreference.com):
ranges::sort(s);Documentation here: https://en.cppreference.com/w/cpp/ranges.
They are called "range adaptors" (weird naming IMHO).
[0] https://www.boost.org/doc/libs/1_72_0/libs/range/doc/html/in...
The committee is very reluctant to break old code. That's one of the reasons the language as documented is so large.
That being said it's not clear to me what would have broken by putting sort(x) into std:: as you recommend.
template<typename T> void sort(T& t) {
std::sort(std::begin(t), std::end(t));
}First, at the time the language did not have enough forwarding capabilities, so you would have needed a lot of overloads to handle const and non const containers.
Second getting anything approved in committee is a huge effort so often proposals are stripped to the bare minimum; in particular the STL was already huge and Stepanov tried to include only what he thought were the fundamental components.
The new ranges have been in development for almost 10 years (arguably they suffered a bit of mission creep), so it is not just a matter of adding range overloads for functions.
What would otherwise be a trivial one liner with something like transform suddenly turns into a 3 line call