C++ 使用声明包含未展开的参数包

C++ 使用声明包含未展开的参数包,c++,c++11,c++14,variadic-templates,using-declaration,C++,C++11,C++14,Variadic Templates,Using Declaration,如何编译此代码 struct type1 {}; struct type2 {}; struct handler1 { void handle(type1){} }; struct handler2 { void handle(type2){} }; template <typename... Handlers> struct TheHandler : Handlers... { using Handlers::handle...; // DOESN'T

如何编译此代码

struct type1 {};
struct type2 {};

struct handler1
{
    void handle(type1){}
};

struct handler2
{
    void handle(type2){}
};

template <typename... Handlers>
struct TheHandler : Handlers...
{
    using Handlers::handle...; // DOESN'T COMPILE
};

TheHandler<handler1, handler2> handler;
handler.handle(type1());
struct type1{};
结构类型2{};
结构句柄1
{
无效句柄(类型1){}
};
结构句柄2
{
无效句柄(类型2){}
};
模板
结构处理程序:处理程序。。。
{
使用处理程序::handle…;//不编译
};
处理者;
handler.handle(type1());

在C++17中添加了使用带有参数包的
,因此您的代码

作为C++14的变通方法,可以使用递归。演示如何执行此操作:

template <typename Handler0, typename... Handlers>
struct TheHandler : Handler0, TheHandler<Handlers...>
{
    using Handler0::handle;
    using TheHandler<Handlers...>::handle;
};

template <typename Handler>
struct TheHandler<Handler> : Handler
{
    using Handler::handle;
};
模板
结构TheHandler:Handler0,TheHandler
{
使用Handler0::handle;
使用handler::handle;
};
模板
结构处理器:处理器
{
使用Handler::handle;
};


如果您愿意,可以实现对数递归深度。

。它是在C++17中添加的(使用扩展参数包的
)。它在C++14中作为编译器工作extension@Justin谢谢,但我暂时还停留在C++14上。与所有的参数包扩展一样,如果我没有弄错的话,你可以用递归重写它,您可以按照论文中建议的使用
参数包扩展来用递归重写这个:如果
处理程序
不应该继承
Handler0
@passertrue,则将继承委托给包装类,但我认为这很好,因为这就是问题中的作用