std::ranges may not deliver the performance that you expect
lemire.me·10h·
Discuss: Hacker News

Good engineers seek software code that is ‘simple’ in the sense that we can read and understand it quickly. But they they also look for highly performant code.

For the last 20 years, we have been offering programmers the possibility to replace conventional for loops with a more functional approach. To illustrate, suppose that you want to extract all even integers from a container and create a new container. In conventional C++, you would proceed with a loop, as follows.

std::vector<int> even_numbers;
for (int n : numbers) {
if (n % 2 == 0) {
even_numbers.push_back(n);
}
}

In recent versions of C++, we have std::ranges which allows us to rewrite the code without a …

Similar Posts

Loading similar posts...