jeudi 22 décembre 2016

preferred way to pass function template argument [duplicate]

This question already has an answer here:

I recently saw a code like this

template<class F> void foo(const F& f){...}

which jumped to my sight immidiately, since I am rather used to

template<class F> void foo(F f){...}

Now that I am thinking of it I do not see the good reason to prefer one to another (at least in serial code). Moreover there is another way to do that

template<class F> void foo(F&& f){...}

which is probably better then the other two, but still I am not sure. So what is the right way to pass the callables as a template parameter nowadays?

Aucun commentaire:

Enregistrer un commentaire