Could this seemingly practical `requires` C++20 form of disambiguation of base method ever work in the future?
04:28 21 May 2026

This is more a question of opinion, targeted mainly at C++20 language lawyers and compiler backend engineers. It probably has a lot to with the specific compiler implementations, and the hurdles they would impose on achieving this? It is about whether such pattern has been attempted before, proposed before, and so on. I'm not very familiar of who and how to approach this, so I'm starting off here for general advice.

Some context: I'm trying to create statically composable templated containers through template metaprogramming, deducing this, and requires.
Here's what I tried to do:

template
struct A {
   template requires (SELECTOR == ID)
   auto Get(this auto&&) { /*implementation*/ }
};

template
struct B {
   template requires (SELECTOR == ID)
   auto Get(this auto&&) { /*implementation*/ }
};

struct Container : A<0>, A<1>, B<2> {};

static_assert(requires (Container c) {
   c.Get<0>();
   c.Get<1>();
   c.Get<2>();
});

To me, this method of disambiguation feels very intuitive and efficient, because it completely avoids writing specifically named delegators in struct Container, or utilizing other boilerplate patterns. Sadly it doesn't work, because disambiguation happens before any requires considerations.

Is it impossible for constraints to be considered while disambiguating, and would it interfere too much with other C++ features?

Do you have any suggestions on how to elegantly circumvent the current compiler limitations and make this work?

templates language-lawyer c++20 multiple-inheritance requires-expression