0

Consider the following code:

template <class...> struct base {};
template <class... T> struct intermediate: base<void, T...> {};
template <class... T> struct derived: base<T...>, intermediate<T...> {};

using type1 = derived<int>::intermediate::base; // works
using type2 = derived<int>::base; // ambiguous

Would there be a way to make it work without ambiguity so that derived<int>::base means the most "direct" base class in the hierarchy (in this example base<int>). Template metaprogramming is welcomed.

Vincent
  • 57,703
  • 61
  • 205
  • 388

1 Answers1

1

If appropriate, you might add alias in derived, so you can use them from outside:

template <class... Ts> struct derived: base<Ts...>, intermediate<Ts...>
{
    using DirectBase = base<Ts...>;
    using IndirectBase = typename intermediate<Ts...>::base;
};

And then

using type1 = derived<int>::IndirectBase ;
using type2 = derived<int>::DirectBase ;

I see no ways to disambiguate.

There was proposal for std::bases std::direct_bases which might help, but rejected.

Jarod42
  • 203,559
  • 14
  • 181
  • 302