How do I get this code to compile?
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());
using with parameter packs was added in C++17, so your code would just work in C++17.
As a workaround for C++14, you can use recursion. The proposal for using... shows how to do this:
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;
};
On Godbolt
It is possible to achieve logarithmic recursion depth, if you wish to do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With