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

Why use concepts instead of unconstrained templates?

Beginner

Answer

Unconstrained templates accept any type and only fail deep inside instantiation with confusing errors, and they can silently participate in overload resolution for wrong types. Concepts document intent, reject invalid types at the interface with clear messages, improve tooling/IDE support, and make generic code self-explanatory and safer.
Real-world example Adding concepts to a library's templates turns baffling instantiation errors into clear, early diagnostics.

Common follow-ups: What problem do unconstrained templates have? | How do concepts document intent?