10
votes

Is there any way one can alias a nested template class with a using keyword? Something like this

template <typename... Types>
struct Something {
    template <typename... TypesTwo>
    struct Another {};
};

template <typename... Types>
template <typename... TypesTwo>
using Something_t = typename Something<Types...>::template Another<TypesTwo...>;

int main() {
    Something_t<int><double>{};
    return 0;
}

This answer template template alias to a nested template? shows a way to do that but that will no longer work if both the parameter packs are variadic, as the compiler will not know where to start and where to end the type lists.

2
Why do you need such specific way? You can change code slightly and use similar code Something_t<int>::Something2<double> - LmTinyToon
@LmTinyToon It is possible to do without it but I am just wondering if it is a thing. - Curious
@LmTinyToon Because he's Curious... :P - 101010
I don't know about an alias, but you might be able to build something similar using an old-school struct-with-typedef by using a delimiter type. - cdhowie
@cdhowie you mean a delimiter in between the type lists to separate them? - Curious

2 Answers

2
votes

Not exactly what you asked but... if you can wrap your variadic type lists as arguments of tuples (or similar classes)...

#include <tuple>

template <typename ... Types>
struct Something
 {
   template <typename ... TypesTwo>
   struct Another {};
 };

template <typename, typename>
struct variadicWrapper;

template <typename ... Ts1, typename ... Ts2>
struct variadicWrapper<std::tuple<Ts1...>, std::tuple<Ts2...>>
 { using type = typename Something<Ts1...>::template Another<Ts2...>; };

template <typename T1, typename T2>
using Something_t = typename variadicWrapper<T1, T2>::type;

int main()
 {
   Something_t<std::tuple<int>, std::tuple<double>>{};
 }
0
votes

Not a standalone answer, but an addition to max66's answer:

You could have tried this:

template<typename ... TT, typename ... TTT>
using Alias = typename Something<TT...>::Another<TTT...>;

Looks really nice at first, doesn't it?

Problem then, however will already be with one single template parameter:

Alias<int> a;

Which one is it now? Something<int>::Another<> or Something<>::Another<int>? And if you have more parameters, how to distribute? No chance to get a meaningful solution. So no, you can't do that directly, you have to help yourself with tricks such as max66 proposed...