在11 C++之前我有这样的事情:
template<class T,class U,class V>
struct Foo : T,U,V {
bool init() {
if(!T::init() || !U::init() || !V::init())
return false;
// do local init and return true/false
}
};
Run Code Online (Sandbox Code Playgroud)
我想将其转换为C++ 11可变参数语法,以获得灵活长度参数列表的好处.我理解使用递归解压缩模板arg列表的概念,但我无法看到正确的语法.这是我尝试过的:
template<typename... Features>
struct Foo : Features... {
template<typename F,typename... G>
bool recinit(F& arg,G&& ...args) {
if(!F::init())
return false;
return recinit<F,G...>(args...);
}
bool init() {
// how to call recinit() from here?
}
};
Run Code Online (Sandbox Code Playgroud)
我更喜欢对基类init()函数的调用顺序是从左到右,但它并不重要.