0

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
};
JeJo
  • 30,635
  • 6
  • 49
  • 88
jorgander
  • 540
  • 1
  • 4
  • 12
  • 3
    Don't you want `typedef std::tuple::value_type...> tuple;` – Jerry Jeremiah Aug 13 '20 at 21:08
  • Unrelated: can't be just `using tuples = std::tuple;`?? Do not understand why you need the `value_type` of `foo`: – JeJo Aug 13 '20 at 21:23
  • @JeJo In this contrived example, yes. but my actual code is more complicated and doesn't follow the pattern that `foo::value_type` will be the same as `T`. – jorgander Aug 13 '20 at 21:28

2 Answers2

3

If you meant foo instead of bar in your typedef, you are just missing the typename keyword before:

template <typename ... T>
struct aggregate_of_foo
{
   using tuple_foo =  std::tuple<typename foo<T>::value_type...>;
                      //         ^^^^^^^^
};

Also note that I named it as tuple_foo because which makes more sense than having just tuple.

JeJo
  • 30,635
  • 6
  • 49
  • 88
1

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
};
cigien
  • 57,834
  • 11
  • 73
  • 112
asmmo
  • 6,922
  • 1
  • 11
  • 25