0

I know the types of the variadic arguments so I am trying to store them in a pre-defined tuple.

Here is my code:

class data
{
public:
    std::tuple<unsigned long long, char, unsigned short, bool, unsigned int, int, float, double, std::string> tpl;
};

data d;

template<typename...Args>
void func(Args...args)
{
    // stores the arguments in d.tpl
}

int main()
{
    func(234, 'g', 34.8f, "Hello World!");
}

anom
  • 41
  • 6
  • Related? [How can I iterate over a packed variadic template argument list?](https://stackoverflow.com/q/7230621/10871073) – Adrian Mole Aug 22 '22 at 09:19
  • I'm trying to store variadic arguments of known type to a tuple, so that doesn't really help. – anom Aug 22 '22 at 09:31
  • Hmm. I was thinking of posting an answer but it would be *extremely* similar to the answer given on the linked question - the one using the `std::any` type. – Adrian Mole Aug 22 '22 at 09:32
  • 1
    You might be looking for `((std::get(d.tpl) = args), ...);` [Demo](https://godbolt.org/z/4faoMbPqx). Except that you are passing a `const char*` to `func`, but the tuple doesn't have an element of type `const char*`. – Igor Tandetnik Aug 22 '22 at 15:37
  • For some reason though, there are gaps between some of the elements. – anom Aug 23 '22 at 06:38

0 Answers0