Question: I have a template class where each template argument stands for one type of value the internal computation can handle. Templates (instead of function overloading) are needed because the values are passed as boost::any and their types are not clear before runtime. 

To properly cast to the correct types, I would like to have a member list for each variadic argument type, something like this:

```
template<typename ...AcceptedTypes> // e.g. MyClass<T1, T2>
class MyClass {
    std::vector<T1> m_argumentsOfType1;
    std::vector<T2> m_argumentsOfType2; // ...
};

```

Or alternatively, I'd like to store the template argument types in a list, as to do some RTTI magic with it (?). But how to save them in a std::initializer\_list member is also unclear to me.

Thanks for any help!

Answer: 
There is a proposal to allow this kind of expansion, with the intuitive syntax: [P1858R1 Generalized pack declaration and usage](https://wg21.link/p1858r1). You can also initialize the members and access them by index. You can even support structured bindings by writing `using... tuple_element = /*...*/`:

```
template <typename... Ts>
class MyClass {
    std::vector<Ts>... elems;
public:
    using... tuple_element = std::vector<Ts>;

    MyClass() = default;
    explicit MyClass(std::vector<Ts>... args) noexcept
        : elems(std::move(args))...
    {
    }

    template <std::size_t I>
        requires I < sizeof...(Ts)
    auto& get() noexcept
    {
        return elems...[I];
    }

    template <std::size_t I>
        requires I < sizeof...(Ts)
    const auto& get() const
    {
        return elems...[I];
    }

    // ...
};

```

Then the class can be used like this:

```
using Vecs = MyClass<int, double>;

Vecs vecs{};
vecs.[0].resize(3, 42);

std::array<double, 4> arr{1.0, 2.0, 4.0, 8.0};
vecs.[1] = {arr.[:]};

// print the elements
// note the use of vecs.[:] and Vecs::[:]
(std::copy(vecs.[:].begin(), vecs.[:].end(),
           std::ostream_iterator<Vecs::[:]>{std::cout, ' '},
 std::cout << '\n'), ...);

```
Here is a less than perfectly efficient implementation using `boost::variant`:

```
template<typename ... Ts>
using variant_vector = boost::variant< std::vector<Ts>... >;

template<typename ...Ts>
struct MyClass {
  using var_vec = variant_vector<Ts...>;
  std::array<var_vec, sizeof...(Ts)> vecs;
};

```

we create a variant-vector that can hold one of a list of types in it. You have to use `boost::variant` to get at the contents (which means knowing the type of the contents, or writing a visitor).

We then store an array of these variant vectors, one per type.

Now, if your class only ever holds one type of data, you can do away with the array, and just have one member of type `var_vec`.

I cannot see why you'd want one vector of each type. I could see wanting a vector where each element is one of any type. That would be a `vector<variant<Ts...>>`, as opposed to the above `variant<vector<Ts>...>`.

`variant<Ts...>` is the `boost` union-with-type. `any` is the `boost` smart-`void*`. `optional` is the `boost` there-or-not.

```
template<class...Ts>
boost::optional<boost::variant<Ts...>> to_variant( boost::any );

```

may be a useful function, that takes an `any` and tries to convert it to any of the `Ts...` types in the `variant`, and returns it if it succeeds (and returns an empty `optional` if not).