c++c++20stdtuplefold-expression

Using parameter pack on nested classes to declare a tuple


I'm trying to declare a tuple which types are based on types that are declared inside classes. I'm trying the following code :

struct A
{
    using T = int;
};

struct B
{
    using T = float;
};

template <class ... Structs>
struct C
{
    std::tuple<(typename Structs::T), ...> t;
};

C<A,B> c;

But, I am getting an error operand of fold expression has no unexpanded parameter packs on the line where I am declaring the tuple, yet its declaration contains Structs which is unexpanded.

Am I missing something here?


Solution

  • Syntax is without comma, i.e:

    template <class ... Structs>
    struct C
    {
        std::tuple<typename Structs::T...> t;
    };