is there in c++ a way to capture functions witch the same name into one function object that can be passed as a callback with static dispatch?
#include <cstdio>
using std::printf;
void foo(int a) {
printf("foo a %d\n", a);
}
void foo(float b) {
printf("foo b %f\n", b);
}
struct A {
int a;
float b;
void operator()(int a) {
printf("A a: %d\n", a+a);
}
void operator()(float b) {
printf("A b: %f\n", b*b);
}
};
template <typename Func>
void foobar(Func func) {
// static dispatch
func(3);
func(2.125f);
}
int main() {
int a = 123;
float b = 1.23f;
foobar(A{a,b}); // this is ok, but I have to write that struct manually
foobar(foo); // ERROR could not infer tempate argument, but this is what I want.
foobar([](int a){ printf("λa "); foo(a); }
(float b){ printf("λb "); foo(b); });
// ERROR fictional syntax that doesn't exist
}