1

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?

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.