Advantages of Concepts
Get familiar with the advantages of the concepts.
We'll cover the following
More generally, what are the advantages of concepts?
Advantages
-
Requirements for template parameters are part of the interface.
-
The overloading of functions and specialization of class templates can be based on concepts.
-
Concepts can be used for function templates, class templates, and generic member functions of classes or class templates.
-
You get improved error messages because the compiler compares the requirements of the template parameters with the given template arguments.
-
You can use predefined concepts or define your own.
-
The usage of
auto
and concepts is unified. Instead ofauto
, you can use aconcept
. -
If a function declaration uses a concept, it automatically becomes a function template. Writing function templates is, therefore, as easy as writing a function.
The long, long history
The first time I heard about concepts was around 2005 - 2006. They reminded me of Haskell type classes. Type classes in Haskell are interfaces for similar types. Here is a part of Haskell’s type classes hierarchy:
Get hands-on with 1200+ tech skills courses.