C++ › Concepts & Constraints

How do concepts improve template error messages?

Beginner

Answer

Without concepts, using a template with an unsupported type produces long, cryptic errors deep inside the template's body. Concepts check requirements at the call site and report a concise message like 'constraint not satisfied' naming the failed requirement, so mistakes are caught early and explained clearly.
template <class T> requires std::equality_comparable<T>
bool same(T a, T b) { return a == b; }
Real-world example Passing a non-comparable type now yields 'does not satisfy equality_comparable' instead of a wall of template errors.

Common follow-ups: Where is the constraint checked? | What kind of message do you get?