template <typename T>
void f1(T t, int a, int b) {
t(a, b);
}
void f2(void(*g)(int, int), int a, int b)
{
g(a, b);
}
void g (int a, int b)
{
}
int main()
{
f1([](int a, int b)
{
}, 1, 2);
f2(&g, 1, 2);
}
My question is: do f1and f2suffer from the same latency of indirect addressing to get the address of the executable function (given that lambda is implemented as a function object)?
What if lambda was not built in?
Note. I declared the function f1 as a template in order to leave the output of the lambda-type parameter to the compiler (instead of, for example, forcing the std function to be used, I’m not sure if it matters, though).
source
share