C++20 Ranges
Raw Loops to Ranges Most C++ code does not begin with elegant abstractions. It begins with simple loops and a problem to solve. It starts where a great deal of C++ starts: a flat vector, a few nested loops, and a stack of intermediate containers that exist only to feed the next loop in line. As the code grows, patterns emerge, abstractions appear, and the language offers better ways to express intent. One such addition is C++20 ranges, which is what this post explores. And there are many reasons why it took so long to become practical in production code. In any reasonably sized engineering organization, the choice of compiler is rarely driven by a single team. ABI compatibility requirements, toolchain support, third-party dependencies, and long-term maintenance concerns all have a say, and the lowest common denominator often wins. It is a shared contract. Every team, every internal library, and every third-party product linked into the build supports a particular set o...