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;};