将每个可变参数模板参数放入容器
Put each variadic template argument into container
在现代 C++ 中有没有一种方法可以将每个可变参数模板参数放入 std::tuple
中的容器中?例如:
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;
}
不必使用元组,只要我得到一个 class 并且每个可变参数模板参数的最终结果都存储在一个容器中,例如 std::vector
.
is there a way to make the inner class store std::tuple<std::vector<int>, std::vector<char>, std::vector<float>
您只需将 T
可变参数列表解包到 std::tuple<std::vector<...>>
.
我是说
template<class ... T>
class MyClass {
private:
std::tuple<std::vector<T>...> myTuple;
}; // ...........^^^^^^^^^^^^^^
在现代 C++ 中有没有一种方法可以将每个可变参数模板参数放入 std::tuple
中的容器中?例如:
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;
}
不必使用元组,只要我得到一个 class 并且每个可变参数模板参数的最终结果都存储在一个容器中,例如 std::vector
.
is there a way to make the inner class store
std::tuple<std::vector<int>, std::vector<char>, std::vector<float>
您只需将 T
可变参数列表解包到 std::tuple<std::vector<...>>
.
我是说
template<class ... T>
class MyClass {
private:
std::tuple<std::vector<T>...> myTuple;
}; // ...........^^^^^^^^^^^^^^