I have a class that is expected to take std::tuple
of certain types (arbitrary count is allowed) as a template argument. I want to declare a tuple of vectors of the types. For instance, I have
template <typename T>
class MyClass {/*...*/}
I instantiate it
MyClass<std::tuple<int, bool>> my_class;
and I aim to create a field like this
std::tuple<std::vector<int>, std::vector<bool>> my_tuple;
I know that if I had a class definition
template <typename... T>
class MyClass2 {/*...*/}
I could instantiate it by passing the data types without a tuple
MyClass<int, bool> my_class2;
and then simply create the field
std::tuple<std::vector<int>, std::vector<bool>> my_tuple2;
using
std::tuple<std::vector<T>...> my_tuple2;
Hence, I was thinking that I should somehow unpack the data types from the tuple. Is it possible?
Yes, and to add to cigien's answer, another way to go about it would be to unpack it through a template specialization.
template<typename Tuple>
class MyClass;
template<typename... Ts>
class MyClass<std::tuple<Ts...>>
{
// ...
using VectorTuple = std::tuple<std::vector<Ts>...>;
// ...
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With