假设我使用可变参数模板作为类型列表:
template <typename ... Types> struct tl {};
using my_list = tl<MyTypeA, MyTypeB, MyTypeC>;
现在我想为每种类型调用一个模板函数,例如:
myFunc<MyTypeA>();
myFunc<MyTypeB>();
我该如何实现这一目标?
最佳答案
使用 c++17,您可以使用 fold expressions .
template <typename ... Types>
void callMyFunc(my_list<Types...>) {
(myFunc<Types>(), ...);
}
关于c++ - 迭代 C++ 可变参数模板类型列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65215959/