C++23: Syntactic Sugar with Deducing This
The article explores the Curiously Recurring Template Pattern (CRTP) in C++ and its usage in implementing static polymorphism. The CRTP is a widely used idiom in C++ and involves a class template Base being derived from a class Derived, with Derived serving as a template argument for Base. This pattern allows for compile-time static polymorphism without the need for runtime pointer indirection.
The article highlights the changes introduced in C++23 that make the implementation of CRTP more concise and readable. With the introduction of deducing this, the explicit object parameter in the CRTP acronym can be removed. This allows for the type of the explicit object parameter to be deduced to the derived type and perfectly forwarded. The article provides an example of a C++23-based implementation of CRTP and demonstrates how the corresponding virtual function implementation is called.
Additionally, the article briefly mentions the use of deducing this for recursive lambdas, although the author expresses reservations about their complexity and prefers concise and self-documenting lambdas.
For developers interested in C++ and its latest features, the article offers insights into the CRTP and the improvements introduced in C++23, making it a valuable read for staying updated with the language's advancements.