Multiple Destructors with C++20
Explore how to use C++20 concepts and requires clauses to create multiple destructors in class templates. Understand how constraints affect destructor selection and the current compiler support challenges.
We'll cover the following...
We still have a class template, but instead of std::conditional, we use the trailing requires clause to provide an overload for the destructor.
Remember we learned earlier that, in class templates, we can provide function overloads using different constraints. This is true even for constructors and destructors.
In the example above, we first wrote a destructor with a requires clause on line 10. Then, we also provided the default implementation without specifying any constraint.
In the requires clause, we specify a constraint that makes it a valid overload only for types that are not trivially destructible. ...