What is 'deducing this' in C++23, and how does it simplify the CRTP pattern?
Last updated
"Deducing this" (explicit object parameter) lets a member take its object as an explicit first parameter, e.g.
this auto&& self. The object's actual type and cv/ref qualifiers are deduced, so one template replaces const/non-const and lvalue/rvalue overloads.For CRTP (a base templated on its derived class), the base becomes a plain class.
selfalready has the derived type, so theDerivedtemplate parameter andstatic_cast<Derived&>(*this)disappear.Caveat: such members cannot be
staticorvirtual, and the implicitthispointer is not used inside them.
- https://gist.github.com/MangaD/a5c5d430f8ef0d791b5a4f6664da1b95
- https://devblogs.microsoft.com/cppblog/cpp23-deducing-this/
- https://www.geeksforgeeks.org/cpp/cpp-23-standard/
- https://news.ycombinator.com/item?id=36663947
- https://github.com/unrays/exotic-crtp
- https://stackoverflow.com/questions/78201757/crtp-and-alternative