For example, I have a function template
template<class Fun>
void Foo(Fun f)
{
...
}
And the argument is a function object or a function pointer. If it is a normal function pointer, the performance is not good since the function cannot be inline. How about using a lambda function here? Thanks.
Foo. It would have to notice that the function pointer variable was initialized at line X with function Y, no chance occurred for it to be modified before it was called on line Z, and replace the pointer access at Z with a direct call to Y. It isn't completely trivial: once things become pointers, a compiler could just give up optimizing. And it is fragile: a seemingly innocuous operation could convince the compiler that the pointer could be modified.