jeudi 10 août 2017

Why to std::forward a callable before calling it? [duplicate]

This question already has an answer here:

Often people std::forward a callable object before calling it like this (example):

template <typename F, typename ...Args>
void call(F &&f, Args &&...args)
{
    std::forward<F>(f) ( // <<< -- question
        std::forward<Args>(args)...  
    );
}

What's the benefit of std::forward-ing f in the example above compared to simple f(std::forward<Args>(args)...?

Aucun commentaire:

Enregistrer un commentaire