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: 
An alternate solution that doesn't use tuples is to use CRTP to create a class hierarchy where each base class is a specialization for one of the types:

```
#include <iostream>
#include <string>

template<class L, class... R> class My_class;

template<class L>
class My_class<L>
{
public:

protected:
  L get()
  {
    return val;
  }

  void set(const L new_val)
  {
    val = new_val;
  }

private:
  L val;
};

template<class L, class... R>
class My_class : public My_class<L>, public My_class<R...>
{
public:
  template<class T>
  T Get()
  {
    return this->My_class<T>::get();
  }

  template<class T>
  void Set(const T new_val)
  {
    this->My_class<T>::set(new_val);
  }
};

int main(int, char**)
{
  My_class<int, double, std::string> c;
  c.Set<int>(4);
  c.Set<double>(12.5);
  c.Set<std::string>("Hello World");

  std::cout << "int: " << c.Get<int>() << "\n";
  std::cout << "double: " << c.Get<double>() << "\n";
  std::cout << "string: " << c.Get<std::string>() << std::endl;

  return 0;
}

```
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).