Consider the following two fragments:
Exhibit A :
template<typename CalcFuncT> int perform_calc(CalcFuncT&& calcfunc) { precalc(); int const calc = calcfunc(); postcalc(); return calc; } int main() { perform_calc([]{ return 5 * foobar_x() + 3; });
Figure B :
template<typename CalcFuncT> int perform_calc(CalcFuncT&& calcfunc) { precalc(); int const calc = std::forward<CalcFuncT>(calcfunc)(); postcalc(); return calc; } int main() { perform_calc([]{ return 5 * foobar_x() + 3; });
Diff
precalc(); - int const calc = calcfunc(); + int const calc = std::forward<CalcFuncT>(calcfunc)(); postcalc();
What is the difference (if any) between the generated code of these two code fragments?
In other words, what is the effect of std :: forward mentioned above, if any?
Note that this question does not ask what std :: forward does at all - only what does it do in the above context?
source share