C++23: Deducing This -- Rainer Grimm

grimm-deducingthis.pngAnyone 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.

C++23: Deducing This

By Rainer Grimm

From the article:

Deducing this, sometimes also called explicit object parameter, allows it to make the implicit this pointer of a member function explicit. Like Python, the explicit object parameter must be the first function parameter and is called in C++, by convention, Self and self.
struct Test {

    void implicitParameter();               // implicit this pointer
    void explictParameter(this Self& self); // explicit this pointer
};
Deducing this enables new programming techniques in C++23: deduplication of function overloading based on the object’s lvalue/rvalue value category and constness. Additionally, you can reference a lambda and invoke it recursively. Furthermore, deducing this simplifies the implementation of CRTP

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.