mercredi 9 août 2017

Detect/get captured values of a lambda function

Is there a way to detect and/or retrieve the values captured in a lambda function, statically or dynamically ?

Example, for the use case :

randomFunction([this](){ methodCall(); });

Is this possible ?

void randomFunction(std::function<void()> lambda) {
    ... // Detect if lambda capture is 'this'
    MyClass* obj = /* retrieve lambda capture 'this' */;
    ...
}

Let's say MyClass is known, will always be the same, and all of this occurs in a template function. Is there at least some traits/tricks to distinguish which template function to call according to the lambda captures ?

Aucun commentaire:

Enregistrer un commentaire