Specifying requirements on template arguments with concepts
Template metaprogramming is an important part of the C++ language, empowering the development of general-purpose libraries, including the standard library. However, template metaprogramming is not trivial. On the contrary, complex tasks could be tedious and difficult to get right without a lot of experience. In fact, the C++ Core Guidelines, an initiative created by Bjarne Stroustrup and Herb Sutter, have a rule called Use template metaprogramming only when you really need to, which reasons that:
Template metaprogramming is hard to get right, slows down compilation, and is often very hard to maintain.
An important aspect concerning template metaprogramming has been the specification of constraints for type template parameters in order to impose restrictions on the types a template can be instantiated with. The C++20 concepts library is designed to solve this problem. A concept is a named set of constraints and...