Why use concepts instead of unconstrained templates?
Short 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.
Advertisement
AModel 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.
Likely follow-ups
- What problem do unconstrained templates have? | How do concepts document intent?
Related topics