May 21, 2025May 21 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 with std::ranges::transform! View the full article
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.