3 ms·
IIUC you have this using `ranges` (which itself needs concepts as implemented). With it you can even do : for (int i : ints | std::views::filter(even) | st
by makapuf 6y ago
IIUC you have this using `ranges` (which itself needs concepts as implemented). With it you can even do :
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 https://cppreference.com):
ranges::sort(s);
- dgellow 6y agoWow, that pipe syntax is quite nice! Documentation here: https://en.cppreference.com/w/cpp/ranges https://en.cppreference.com/w/cpp/ranges. They are called "range adaptors" (weird naming IMHO).
- saagarjha 6y agoThey take a range and adapt it into a view, hence the name.
- innot 6y agoThe same functionality has been in boost [0] for quite a while. So, if you can't see the ugly iterators anymore, but have an outdated compiler, this is an option. [0] https://www.boost.org/doc/libs/1_72_0/libs/range/doc/html/index.html https://www.boost.org/doc/libs/1_72_0/libs/range/doc/html/in...
- account42 6y agoI wish they had just added the overloads to the std:: namespace though - breaking a few obscure cases would have been worth that.
- gumby 6y ago> breaking a few obscure cases would have been worth that 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.