Concepts

Table of Contents

Concepts

Concepts allow functions, class templates, and function templates to be constrained by some binary condition:

template<typename T>
concept Hashable = requires(T a) {
    { std::hash<T>{}(a) } -> std::convertible_to<std::size_t>;
};
 
// Constrained C++20 function template:
template<Hashable T>
void f(T) {}