Search code examples
c++c++11templatesvariadic-templatesclass-template

How to expand parameter pack for dependent types?


What is the syntax for expanding a parameter pack where the types I want are dependent on the types directly in the pack?

For example:

template <typename T>
struct foo
{
   typedef T value_type;
};

template <typename ... T>
struct aggregate_of_foo
{
   typedef std::tuple<foo<T>::value_type...> tuple; // MSVC compiler error here
};

Solution

  • You have to use the keyword typename because value_type is a dependent name in this context.

    template <typename ... T>
    struct aggregate_of_foo
    {
        typedef std::tuple<typename foo<T>::value_type...> tuple; //here
    };