mercredi 6 avril 2016

Best way to pass function as parameter

In C++ there are several ways to pass function as parameter, but I would like to understand whats is the vantages and advantages of each one, for example, looking the signature of functions from algorithm:

template <class RandomAccessIterator, class Compare>
  void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);

Why std algorithm uses template for pass function instead of std::function?

Why thread uses move semantic and algorithms functions don't?

template <class Fn, class... Args>
explicit thread (Fn&& fn, Args&&... args);

PS: I am disregarding the ways used in C as function pointers.

Aucun commentaire:

Enregistrer un commentaire