Ezaren
Ezaren

Reputation: 23

Put each variadic template argument into container

Is there a way in modern C++ to put each of the variadic template arguments into a container within a std::tuple? For example:

template<class ... T>
class MyClass {
private:
std::tuple<T...> myTuple;
};

int main() {
MyClass<int, char, float> test; //inner class stores an std::tuple<int, char, float>
//is there a way to make the inner class store std::tuple<std::vector<int>, std::vector<char>, std::vector<float>>
return 0;
}

Tuples do not have to be used, as long as I get a class with an end result of each variadic template argument being stored in a container like a std::vector.

Upvotes: 1

Views: 87

Answers (1)

max66
max66

Reputation: 66200

is there a way to make the inner class store std::tuple<std::vector<int>, std::vector<char>, std::vector<float>

You have simply to unpack the T variadic list inside std::tuple<std::vector<...>>.

I mean

template<class ... T>
class MyClass {
   private:
      std::tuple<std::vector<T>...> myTuple;
}; // ...........^^^^^^^^^^^^^^

Upvotes: 2

Related Questions