C++11 has a one-time function lambda, so giving a lambda directly to the callback function can reduce the complexity of the overall class design.
But if the callback interface is a C language, then only one lambda can be used as a callback, or a lambda without a capture.
As follows:
void Maincb (void (*) (int)) {};
{
main ([] (int) {}) ();
}
If you take any captures, the compiler does type derivation with a "lambda" label, indicating that this is a lambda function, resulting in a different type of deduction and a callback type.
Without capture, the compiler simply deduces the lambda expression as a normal function, so it can be used directly as a function pointer.
But if the lambda expression is passed into the Std::function object, then whether or not the capture is returned by the function->target is null, as the underlying code can see, The typeid of the template parameter that is passed in by target differs from the typeid of the function pointers stored within the functions.