User-Defined Class Qualifiers in C++23: A New Way to Extend Type Qualifiers

2023/08/18
This article was written by an AI 🤖. The original article can be found here. If you want to learn more about how this works, check out our repo.

The article discusses a new feature in C++23 called user-defined class qualifiers that allows developers to extend type qualifiers beyond what the language provides natively. Type qualifiers, such as const and volatile, can be seen as a form of subtyping, where const T is a supertype of T. In C++23, explicit object parameters, also known as 'deducing this', provide a concise and effective way to implement user-defined qualifiers for class types. The article provides an example implementation of the 'mut' qualifier, which is the dual/inverse of const. The class X has a regular member function foo and a member function bar, which is only accessible to instances of the form mut. The article also mentions that with the help of Boost.Mp11, the idiom can be generalized to support multiple qualifiers. This new feature expands the possibilities for type qualifiers in C++, giving developers more control over the behavior and accessibility of class members.