#include <iostream>
template<typename Functor, unsigned = 0>
struct Wrapper
{
static void DoCallback(Functor f)
{
f();
}
};
template<typename Functor>
struct Wrapper<Functor, 1>
{
static void DoCallback(Functor f)
{
f(1, 2);
}
};
template<typename Functor>
void DoCallback(Functor f)
{
Wrapper<Functor>::DoCallback(f);
}
struct f1
{
void operator()(){std::cout << "f1" << std::endl;}
};
struct f2
{
void operator()(int x, int y){std::cout << "f2 with " << x << ", " << y << std::endl;}
};
int main()
{
f1 a;
f2 b;
DoCallback(a);
DoCallback(b);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdGVtcGxhdGU8dHlwZW5hbWUgRnVuY3RvciwgdW5zaWduZWQgPSAwPgpzdHJ1Y3QgV3JhcHBlcgp7CiAgICBzdGF0aWMgdm9pZCBEb0NhbGxiYWNrKEZ1bmN0b3IgZikKICAgIHsKICAgICAgICBmKCk7CiAgICB9Cn07CnRlbXBsYXRlPHR5cGVuYW1lIEZ1bmN0b3I+CnN0cnVjdCBXcmFwcGVyPEZ1bmN0b3IsIDE+CnsKICAgIHN0YXRpYyB2b2lkIERvQ2FsbGJhY2soRnVuY3RvciBmKQogICAgewogICAgICAgIGYoMSwgMik7CiAgICB9Cn07CnRlbXBsYXRlPHR5cGVuYW1lIEZ1bmN0b3I+CnZvaWQgRG9DYWxsYmFjayhGdW5jdG9yIGYpCnsKICAgIFdyYXBwZXI8RnVuY3Rvcj46OkRvQ2FsbGJhY2soZik7Cn0KCnN0cnVjdCBmMQp7CiAgICB2b2lkIG9wZXJhdG9yKCkoKXtzdGQ6OmNvdXQgPDwgImYxIiA8PCBzdGQ6OmVuZGw7fQp9OwpzdHJ1Y3QgZjIKewogICAgdm9pZCBvcGVyYXRvcigpKGludCB4LCBpbnQgeSl7c3RkOjpjb3V0IDw8ICJmMiB3aXRoICIgPDwgeCA8PCAiLCAiIDw8IHkgPDwgc3RkOjplbmRsO30KfTsKCgppbnQgbWFpbigpCnsKICAgIGYxIGE7CiAgICBmMiBiOwogICAgRG9DYWxsYmFjayhhKTsKICAgIERvQ2FsbGJhY2soYik7Cn0K
prog.cpp: In instantiation of ‘static void Wrapper<Functor, <anonymous> >::DoCallback(Functor) [with Functor = f2; unsigned int <anonymous> = 0u]’:
prog.cpp:22:5: required from ‘void DoCallback(Functor) [with Functor = f2]’
prog.cpp:40:17: required from here
prog.cpp:8:9: error: no match for call to ‘(f2) ()’
prog.cpp:29:8: note: candidate is:
prog.cpp:31:10: note: void f2::operator()(int, int)
prog.cpp:31:10: note: candidate expects 2 arguments, 0 provided