...

/

Functions and Classes

Functions and Classes

Let's learn about coming C++ concepts in detail in this lesson.

Concepts are part of the template declaration.

Functions

Using the concept Sortable.

Implicit

template<Sortable Cont>
void sort(Cont& container){
...
}

The container has to be Sortable.

The implicit version from the left is syntactic sugar to the explicit version:

Explicit

template<typename Cont> 
   requires Sortable<Cont>()
void sort(Cont& container){
    ...
}

Sortable has to be a constant expression that is a predicate. That means that the expression has to be evaluable at compile-time and has to return a boolean.

If you invoke the sort algorithm with a container lst that is not sortable, you will get a unique error message from the ...