© Ivor Horton and Peter Van Weert 2020
I. Horton, P. Van WeertBeginning C++20https://doi.org/10.1007/978-1-4842-5884-2_21

21. Constrained Templates and Concepts

Ivor Horton1  and Peter Van Weert2
(1)
Stratford-upon-Avon, Warwickshire, UK
(2)
Kessel-Lo, Belgium
 

Templates define parameterized families of C++ entities such as functions (Chapter 10) or class types (Chapter 17). In practice, templates are mostly parameterized on seemingly arbitrary types. Yet most templates cannot be instantiated for just any type; at least not without error. The binary std::max<>() function template, for instance, can only be instantiated for types that support the < operator. And the std::vector<> and std::optional<> class templates may not be instantiated for reference ...

Get Beginning C++20: From Novice to Professional now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.