I'm currently struggling with the following code, the intent of which is to implement variadic variadic template templates:
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;
};
Ideally, I'd be able to use this template metafunction to achieve the following:
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;
*/
The output of the above would hopefully create new_obj1
and new_obj2
in the form template<int, int, double, double, char, char*, int, double, const char*> struct new_obj[1|2] {};
I'm using gcc 4.6.2 on Windows, which outputs an "expected parameter pack before '...'" for the expansion of "Head<typename TailArgs...>
...".
This error is reproducable with gcc 4.5.1.
See Question&Answers more detail:os