Back to results for “Concepts & Constraints”
C++ › Concepts & Constraints

What are C++20 concepts?

Beginner

Answer

Concepts are named, compile-time predicates that constrain template parameters—specifying the requirements a type must satisfy (e.g., must be sortable, must support +). They make templates clearer, produce far better error messages than raw templates or SFINAE, and let the compiler reject invalid types early with a precise reason.
template <std::integral T>
T doubleIt(T x) { return x + x; }   // T must be an integer type
Real-world example Constraining a numeric template with std::integral gives a clear error when a string is passed.

Common follow-ups: What do concepts constrain? | How do they improve error messages?