C++ › Concepts & Constraints
What are the different ways to apply a constraint to a template?
IntermediateAnswer
You can constrain templates via: a concept name in place of typename (template <std::integral T>), a requires clause (template <class T> requires C<T>), a trailing requires clause after the function signature, or the abbreviated function template syntax using a concept with auto (void f(std::integral auto x)). All express the same kind of requirement.
void f(std::integral auto x); // abbreviated
template <class T> requires C<T> void g(T); // requires clauseReal-world example The team uses the abbreviated 'std::sortable auto' parameter form for concise constrained functions.