There is so much talk about new C ++ forwarding links. However, sometimes in a specific situation it is still not clear to me whether they provide any advantage or not.
It is clear that passing heavy state functors (like random number generators) by value is not a good idea. So let me use the links. Okay, but...
... is there any advantage to using forwarding links such as
template <class T, class Functor>
T func(T x, Functor &&f)
{
T y;
// do some computations involving f(x) and store it in y
return y;
}
instead of const links
template <class T, class Functor>
T func(T x, const Functor &f)
{
T y;
// do some computations involving f(x) and store it in y
return y;
}
in functions that take object objects without sending them?
The main aspect of the issue is the assessment of effectiveness.
source
share