C++20 Ranges Library: Comprehensive Introduction for C++ Programmers

C++20 Ranges Library vs. STL Algorithms: A Performance and Expressiveness Comparison

oğuzhan katlı
2 min readNov 3, 2023
picture from https://www.modernescpp.com/index.php/the-ranges-library-in-c20-design-choices/
picture from Rainer Grimm’s modernescpp.com page


The C++20 ranges library provides a new and modern way to write range-based algorithms. It is more powerful and flexible than the traditional STL algorithms, and it can be used to write more compact (easy to read) and efficient code.

The article shared below compares the ranges library with the traditional STL algorithms in terms of expressiveness, performance, and ease of use. The article also shows that the ranges library offers a number of advantages over the STL algorithms, including:

  • More concise and expressive code: The ranges library provides a number of operators and functions that make it easy to write concise and expressive code. For example, the filter() function can be used to filter a range of elements based on a predicate, without having to write a loop.
  • Better performance: The ranges library has been shown to provide significant performance improvements over the traditional STL algorithms in many cases. This is because the ranges library uses lazy evaluation and pipelining techniques.
  • Ease of use: The ranges library is designed to be easy to use. It provides a number of helper functions and classes that make it easy to get started with the library.

When I started to this article, I thought that the Medium infrastructure would be sufficient. However, at this point, I had to move the blog post I wrote for the Ranges library to another location where I can use Markdown format.

I hope that this change I made has been able to keep the readability of the article at the maximum level and that it has been a comfortable and understandable article for you.

Example code that discussed on the article:

Below example can be also run on Compiler Explorer