How it works...

To best explain how C++20 Concepts will aid in template programming, we will start with a simple example of programming an interface in C++ today. Interfaces define a contract between the implementation of an Application Programming Interface (API) and the user of the API and are heavily used in object-oriented programming to abstract away the interface of an API from its implementation details.

Let's start with the following pure virtual interface:

class interface{public:    virtual ~interface() = default;    virtual void foo() = 0;};

The preceding pure virtual interface in C++ defines a foo() function. Clients of this API do not need to know how foo() is implemented. All they care about is the definition of the interface and the ...

Get Advanced C++ Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.