samedi 8 août 2020

Is there any reason to wrap a Lambda in a named function?

I recently stumbled upon this example code and I was confused:

auto named_funct(const MyClass& some_class)
{
    return [some_class](const MyClass2& some_other_class)
    {
        return some_class <= some_other_class; // some expression between capture and input parameter to the Lambda
    };
}

Is there any reason at all to wrap an anonymous function in a named function? It seems like an extra function call stack is being created for no reason.

Aucun commentaire:

Enregistrer un commentaire