WeSearch

C++26: Ordering of constraints involving fold expressions

·3 min read · 0 reactions · 0 comments · 11 views
#programming#cpp#software development
⚡ TL;DR · AI summary

C++26 introduces a solution to the ambiguity issues in overload resolution involving fold expressions. The new concept of fold expanded constraints allows the compiler to properly recognize and prioritize more constrained overloads. This change addresses limitations present in C++20 and C++23 regarding constraint subsumption.

Key facts
Original article
Sandor Dargo’s Blog
Read full at Sandor Dargo’s Blog →
Opening excerpt (first ~120 words) tap to expand

You have two overloads of g(). One requires A<T> for each element in a pack, the other requires C<T> — where C is a stricter concept that subsumes A. Both apply to the types you’re passing. The compiler should pick the more constrained version. But instead it complains about an ambiguous call.This is a limitation of how C++20 and 23 handle constraints that use fold expressions — fixed in C++26.Constraint subsumption, brieflySubsumption is the compiler’s mechanism for ordering overloads by how constrained they are. If concept C is defined as A && B, then any type satisfying C also satisfies A. The compiler recognizes this and, when resolving an overload, prefers the more constrained one — no ambiguity.As we saw a few years back, subsumption has quirks.

Excerpt limited to ~120 words for fair-use compliance. The full article is at Sandor Dargo’s Blog.

Anonymous · no account needed
Share 𝕏 Facebook Reddit LinkedIn Threads WhatsApp Bluesky Mastodon Email

Discussion

0 comments