I am trying to store a captureless lambda that has a default parameter to a function pointer. I have the below code working for a lambda with a default argument
#include <iostream>
int main()
{
decltype([](int a = 10) { std::cout << a << std::endl;}) my_lambda {};
my_lambda();
my_lambda(21);
return 0;
}
I have also managed to convert to a function pointer
#include <iostream>
using command_t = bool (*)(int);
int main()
{
decltype([](int a = 10) { std::cout << a << std::endl; return true;}) my_lambda {};
command_t testFunction(my_lambda);
//testFunction();
testFunction(21);
return 0;
}
But I lose the default parameter as I cannot uncomment the testFunction() and run it as the compiler tells me that it is expecting a parameter. How can I combine these two concepts and convert these lambdas to a function pointer and keep the default parameter? I am using gcc 10.2. Thanks.