Copying C ++ lambda to a function pointer link

I am not sure that I determined the behavior in the following situation:

Type of my function:

typedef void (*DoAfter_cb_type)(void);

The function that should assign callbacks:

void DoSomething(DoAfter_cb_type & DoAfter_cb)
{
    //...
    DoAfter_cb =  [](){
        //...
    };
}

Subscriber:

DoAfter_cb_type DoAfter_cb = nullptr;

DoSomething(DoAfter_cb);

// Here is something that has to be done after DoSomething but before DoAfter_cb.

if( DoAfter_cb != nullptr){
    DoAfter_cb();
}

As I learned here , lambdas can be implicitly converted to function pointers.

However, thoose are still pointers, and I'm afraid that something important for calling lambda is stored on the stack and will not be available if I just return the link to the function pointer

I need to use function pointers because I do not have access to std :: function in my environment. With std :: function, I would expect the lambda object to be stored in a reference variable, and I would have no problem.

, - ?

+4
1

, - ?

, . , , ++ ([expr.prim.lambda.closure]/6, ):

- - lambda-capture ++ , , . - " to noexcept function", . , function - F, , .

, , , , . "" , .

+4
source

Source: https://habr.com/ru/post/1695798/