c++ - Plantillas variadas variadas
c++11 metaprogramming (1)
Actualmente estoy luchando con el siguiente código, cuyo objetivo es implementar plantillas de plantilla variadic variadic:
template
<
template <typename... HeadArgs> class Head,
template <typename... TailArgs> class...
>
struct join<Head<typename HeadArgs...>, Head<typename TailArgs...>...>
{
typedef Head<typename HeadArgs..., typename TailArgs......> result;
};
Idealmente, podría usar esta metafunción de plantilla para lograr lo siguiente:
template <typename...> struct obj1 {};
template <typename...> struct obj2 {};
typedef join
<
obj1<int, int, double>,
obj1<double, char>,
obj1<char*, int, double, const char*>
>::result new_obj1;
typedef join
<
obj2<int, int, double>,
obj2<double, char>,
obj2<char*, int, double, const char*>
>::result new_obj2;
/* This should result in an error, because there are
different encapsulating objects
typedef join
<
obj1<int, int, double>,
obj1<double, char>,
obj2<char*, int, double, const char*>
>::result new_obj;
*/
Se espera que la salida de lo anterior cree new_obj1
y new_obj2
en la template<int, int, double, double, char, char*, int, double, const char*> struct new_obj[1|2] {};
formulario template<int, int, double, double, char, char*, int, double, const char*> struct new_obj[1|2] {};
Estoy usando gcc 4.6.2 en Windows, que genera un "paquete de parámetros esperado antes de ''...''" para la expansión de " Head<typename TailArgs...>
...".
Intenta algo como esto:
template <typename...> struct join;
template <template <typename...> class Tpl,
typename ...Args1,
typename ...Args2>
struct join<Tpl<Args1...>, Tpl<Args2...>>
{
typedef Tpl<Args1..., Args2...> type;
};
template <template <typename...> class Tpl,
typename ...Args1,
typename ...Args2,
typename ...Tail>
struct join<Tpl<Args1...>, Tpl<Args2...>, Tail...>
{
typedef typename join<Tpl<Args1..., Args2...>, Tail...>::type type;
};