C++23: static operator() and static operator[] -- Sandor Dargo
In this article, we are going to review two new features of C++23. Now the language allows the call operator (operator()) and the subscription operator (operator[]) to be static.
C++23: static operator() and static operator[]
By Sandor Dargo
From the article:
static operator()As we saw earlier in our big C++ algorithms tutorial, function objects are extensively used in the standard library to customise the behaviour of several functions. With the introduction of ranges in C++20 (and of earlier non-standard libraries), the usage of function objects became even more widespread.
Many function objects are extremely simple. Let’s take an implementation of
isEven.auto isEven = [](int i) {return i % 2 == 0;};

The Curiously Recurring Template Pattern (CRTP) is a heavily used idiom in C++. It is similarly resistant to understanding as the classic design pattern visitor I presented in my last post: “
Some time ago I started working on P1705 Enumerating Core Undefined Behavior, I have collected a large set of undefined behavior (UB) during that time. There is going to be a lot of work involved in getting the annex into shape and editing it into the standard. While this work is ongoing, I will take some time to write blog posts to explore the set of undefined behaviors.
Anyone who thinks a small C++ standard follows a significant C++ standard is wrong. C++23 provides powerful extensions to C++20. These extensions include the core language, particularly the standard library. Today, I present a small but very impactful feature of the core language: deducing this.