Concepts in C++20


Details
If you ever read portions of the C++ standard or standard library documentation you may have seen mention of something called "concepts" when it comes to template parameters. The idea was that a template parameter representing a type should model the concept of the template argument. For instance, loosely speaking the ForwardIterator concept models something that has a pointer dereferencing operation and an increment operator to advance the iterator forward.
Concepts have been around for a long time in C++, but they never had a syntactical representation in the language. The problem with Concepts being merely an idea described by prose in the standard, and not a syntactical construct in the language, comes up when you supply a template argument that doesn't correctly model the underlying concept. The end result is euphemistically termed the "error novel": pages and pages of nested error messages from the compiler detailing at the inner most layer of template argument substitution some obscure syntactical or semantic error relating to the supplied template argument.
The standards committee has been working to make C++ simpler to use without relinquishing the power that C++ brings to the table. C++ 20 adopts a syntactical construct to the language for expressing concepts directly so that the compiler can report diagnostics about template parameters with respect to the concept, e.g. "the supplied type does not provide a dereference operator required by the ForwardIterator concept". The Standard Library has been augmented with a variety of concepts for existing components in the library as well as the new components in the library (e.g. ranges).
This month, Richard Thomson will give us an overview of Concepts in C++20. We'll take a look at the following details:
- Concept syntax
- Concepts in the standard library
- Concepts relating to ranges
- Improved error diagnostics (using clang v10.0 in compiler explorer)
This will be a virtual meetup via webex, so BYOB. :)

Concepts in C++20