#include <iostream>
#include <tuple>
class A
{
public:
void doIt() { std::cout << "A" << std::endl; }
};
class B
{
public:
void doIt() { std::cout << "B" << std::endl; }
};
class Visitor {
public:
template <class C>
void operator()(C &c)
{
c.doIt();
}
};
template <class F, class C>
void
visitAll(F visitor, C &&c)
{
visitor(c);
}
template <class F, class C, class... Args>
void
visitAll(F visitor, C &&c, Args... A)
{
visitor(c);
visitAll(visitor, A...);
}
int
main(int argc, char *argv[])
{
visitAll(Visitor(), A(), B());
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dHVwbGU+CgpjbGFzcyBBCnsKcHVibGljOgogICAgdm9pZCBkb0l0KCkgeyBzdGQ6OmNvdXQgPDwgIkEiIDw8IHN0ZDo6ZW5kbDsgfQp9OwoKY2xhc3MgQgp7CnB1YmxpYzoKICAgIHZvaWQgZG9JdCgpIHsgc3RkOjpjb3V0IDw8ICJCIiA8PCBzdGQ6OmVuZGw7IH0KfTsKCmNsYXNzIFZpc2l0b3IgewpwdWJsaWM6CiAgICB0ZW1wbGF0ZSA8Y2xhc3MgQz4KICAgIHZvaWQgb3BlcmF0b3IoKShDICZjKQogICAgewogICAgICAgIGMuZG9JdCgpOwogICAgfQp9OwoKdGVtcGxhdGUgPGNsYXNzIEYsIGNsYXNzIEM+CnZvaWQKdmlzaXRBbGwoRiB2aXNpdG9yLCBDICYmYykKewogICAgdmlzaXRvcihjKTsKfQoKdGVtcGxhdGUgPGNsYXNzIEYsIGNsYXNzIEMsIGNsYXNzLi4uIEFyZ3M+CnZvaWQKdmlzaXRBbGwoRiB2aXNpdG9yLCBDICYmYywgQXJncy4uLiBBKQp7CiAgICB2aXNpdG9yKGMpOwogICAgdmlzaXRBbGwodmlzaXRvciwgQS4uLik7Cn0KCmludAptYWluKGludCBhcmdjLCBjaGFyICphcmd2W10pCnsKICAgIHZpc2l0QWxsKFZpc2l0b3IoKSwgQSgpLCBCKCkpOwogICAgcmV0dXJuIDA7Cn0K