Raw Loops for Performance? -- Sandor Dargo
Using ranges or algorithms has several advantages over raw loops, notably readability. On the other hand, as we’ve just seen, sheer performance is not necessarily among those advantages. Using ranges can be slightly slower than a raw loop version. But that’s not necessarily a problem, it really depends on your use case. Most probably it won’t make a bit difference.
Raw Loops for Performance?
by Sandor Dargo
From the article:
To my greatest satisfaction, I’ve recently joined a new project. I started to read through the codebase before joining and at that stage, whenever I saw a possibility for a minor improvement, I raised a tiny pull request. One of my pet peeves is rooted in Sean Parent’s 2013 talk at GoingNative, Seasoning C++ where he advocated for no raw loops.
When I saw this loop, I started to think about how to replace it:
Please note that the example is simplified and slightly changed so that it compiles on its own.
Let’s focus on
foo, the rest is there just to make the example compilable.It seems that we could use
std::transform. But heck, we use C++20 we have ranges at our hands so let’s go withstd::ranges::transform!


Registration is now open for CppCon 2025! The conference starts on September 13 and will be held
Constexpr has been around for a while now, but many don’t fully understand its subtleties. Andreas Fertig explores its use and when a constexpr expression might not be evaluated at compile time.
C++’s undefined behaviour impacts safety. Sandor Dargo explains how and why uninitialised reads will become erroneous behaviour in C++26, rather than being undefined behaviour.
In the December issue of Overload [
Friday, May 30th, 2025, 10:00 - 18:00 Berlin time (online)