Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to alias a nested template class with variadic parameter packs

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.

like image 300
Curious Avatar asked Mar 15 '17 16:03

Curious


1 Answers

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>>{};
 }
like image 112
max66 Avatar answered Nov 20 '22 10:11

max66