No, there isn't.
In the first construction, the function is passed to the std::function
constructor as int (&) (int)
- a reference to function.
In the second construction, the function is passed to the std::function
constructor as int (*) (int)
- a pointer to function.
The way the callable itself is stored inside the std::function
object is implementation defined.
After construction, both fn1
and fn2
behave exactly the same, and there is no difference.
As for "which one is better" - I would prefer the reference version, as the sentence is less laden with operators, and anyway, my philosophy is to use pointers as little as possible, even if it's the safest pointer possible.