0

I would like to enforce that all types in a parameter pack have a nested type alias declared in them (T), and expand all the T's of the types into a tuple. Is something like this possible? When I try the naiive way below, it doesn't recognize Types::T as a type.

class A { using T = int; };
class B { using T = double; };


template<class ... Types>
class C {
  using tuple_of_types_t        = std::tuple<Types...>;       // of course this works
  using tuple_of_nested_types_t = std::tuple<((Types::T),...)>;  // how do I achieve this?
};
Kyle Beyer
  • 21
  • 2
  • 1
    Use `typename`: `std::tuple;`. [when to use typename, template keywords](https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords) – rafix07 Nov 02 '21 at 13:13
  • note that your `T` in both `A` and `B` is private, which will mess with the type checking – Timo Nov 02 '21 at 13:14
  • `type` is a more regular naming than `T` for typedef. – Jarod42 Nov 02 '21 at 13:15

1 Answers1

1

The compiler needs to be informed that Types::T should be interpreted as a type.

using tuple_of_nested_types_t = std::tuple<typename Types::T...>;
//                                         ^^^^^^^^

See it compile on Compiler Explorer

Drew Dormann
  • 59,987
  • 13
  • 123
  • 180