Reputation: 4710
The following code does not compile with gcc 4.7 (20120114) , but compiles fine with clang++ 3.0. Is this a bug in gcc, clang or just because what I try to do is not allowed in c++11?
template< typename... args >
struct A {
template< typename head, typename... tags >
struct Inner : public Inner<tags...> {
};
template< typename head >
struct Inner<head> {
// assume both args... and tags... must be used to
// calculate TYPE
typedef int TYPE;
};
};
template< typename... args >
struct B : A<args...> {
template<typename... tags>
typename A<args...>::template Inner<tags...>::TYPE x() {
return 0;
}
};
int main(int argc, const char *argv[]) {
B<int, int, int> b;
b.x<char, short, long, double>();
return 0;
}
The code above is a very simplified example of what I try to do, but the essence is that I need both the args... types and the tags... types to calculate the return type of the function. How can this be done?
Upvotes: 1
Views: 443
Reputation: 523164
Not sure if it's a bug of gcc or not, but the standard solution to make it compile on gcc is to declare the empty variadic version and then specialize it:
template <typename... T>
struct Inner;
template <typename Head, typename... Rest>
struct Inner<Head, Rest...> : public Inner<Rest...> { ... };
Demo: http://ideone.com/MFKVY
Upvotes: 3