I need to pass a lambda with captures to a function, but I'm trying to avoid using std::function
because of slow performance, and I'm making a performance critical application. I also would prefer to not use a template because the return type and parameters are specific, but I can use a template if it's the only way.
I already tried ChatGPTs answer and it didnt work:
void my_func(void (*callback)(int, int, int))
{
callback(1, 2, 3);
}
int main()
{
int x = 10;
my_func([&](int a, int b, int c)
{
std::cout << "Example, a + b + c + x: " << a + b + c + x << std::endl;
});
return 0;
}
The error says:
no suitable conversion function from "lambda [](int a, int b, int c)->void" to "void (*)(int, int, int)" exists