Effective this—practical guide to explicit object pointer

Speaker: Dawid Zalewski

Audience level: [ Intermediate | Advanced ]

this is as old as C++. It's been tirelessly passed to every non-static member function by the compiler with us barely noticing. We've had no control over it, and very few reasons to ever spell it out in code.

But with C++23 came the ability to explicitly include this as the first parameter of a member function. What's more, its type need not be restricted to the type of the containing class. The type of this can be deduced, or it can be something completely unrelated, like int. As if that wasn't enough, this is no longer just a pointer but rather a reference or a value.

In this talk, we'll explore the implications of this new feature. We'll start with the basics, reminding what an implicit instance pointer is, and how it's used in the pre-C++23 code. Then, we'll introduce the new syntax of the explicit object pointer, and talk about the intentions conveyed by its different variants. Finally, we'll explore the world of applications for the explicit this. Starting with code deduplication and new ways of forwarding, we'll move on to more advanced topics such as lambdas, template metaprogramming, and reimplementations of popular patterns. By the end of this talk, you'll not only understand the new feature, but you'll start noticing its possible application just about everywhere in your code.