Reputation: 155
Say I have a lambda I want to define. I can do it like this,
auto foo = [] (int x)
{
return x == 42;
};
or this,
std::function<bool(int)> foo = [] (int x)
{
return x == 42;
};
Is there any penalty for doing the second one? Does std::function
have overhead I should be wary of? I don't use it very often; only when doing recursion.
Upvotes: 2
Views: 301
Reputation: 158599
Using std::function does incur a cost for a good discussion of this cost you can read Efficient Use of Lambda Expressions and std::function.
Upvotes: 3