Advertisement
Intermediate C++, Concepts & Constraints

How does concept subsumption affect overload resolution?

Short answer

When multiple constrained overloads match, the compiler prefers the one whose constraints subsume (are more specific/stronger than) the others.

Save C++ mock interview
Advertisement
AModel 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.
Likely follow-ups
  • What does 'subsume' mean? | Which overload is preferred?
Related topics