vendredi 28 juillet 2023

why should I use function instead of named lambdas in C++

Recently I've struggled a lot with function deduction and of course lambdas prove to be more flexible here, but doing so I've came to a question, why should I use function instead of named lambdas?

e.g.

namespace
{
auto foo(auto && arg1, auto && arg2){
    return arg1 + arg2;
}

auto bar = [](auto&& arg1, auto && arg2){
    return arg1 + arg2;
}
}

bar is more flexible while doing templates and stuff, but is there any downsides using bar? performance or memory costs in real programming? I've run some tests with assembly output and bar proves to have even less instructions in some cases.

Aucun commentaire:

Enregistrer un commentaire