是否有任何简单的方法可以访问整个参数包的内部成员?假设您有以下代码
#include <iostream>
class A {
typedef int type;
constexpr static type C = 5;
};
class B {
typedef unsigned type;
constexpr static type C = 6;
};
template <class T1, class ... TList>
std::ostream & printer(std::ostream & out, T1 t1, TList ... plist) {
out << t1 << " ";
return printer(out, plist...);
}
template <class T1>
std::ostream & printer(std::ostream & out, T1 t1) {
return out << t1 << std::endl;
}
template <class ... TList>
std::ostream & proxy(std::ostream & out, TList ... plist) {
return printer(out, std::forward<TList::type ...>(plist::C ...));
}
int main(int argc, const char * argv[])
{
proxy(std::cout, A(), B());
return 0;
}
我希望代理函数解压缩 plist 的成员变量并将它们传递给打印机。有没有一种简单的方法可以在不遍历参数列表的情况下做到这一点?