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

How does concept subsumption affect overload resolution?

Intermediate

Answer

When multiple constrained overloads match, the compiler prefers the one whose constraints subsume (are more specific/stronger than) the others. This lets you write a general constrained template plus a more-constrained specialization, and the most-constrained viable candidate is chosen—cleanly replacing tag dispatch and enable_if priority tricks.
void f(std::integral auto x);              // more constrained
void f(auto x);                            // less constrained
f(5);   // picks the std::integral overload
Real-world example A more-constrained overload for random-access ranges is automatically preferred over the generic one.

Common follow-ups: What does 'subsume' mean? | Which overload is preferred?