In C ++, there are several ways to pass a function as a parameter, but I would like to understand what are the advantages and advantages of each of them, for example, looking at the signature of functions from the algorithm:
template <class RandomAccessIterator, class Compare>
void sort (RandomAccessIterator first, RandomAccessIterator last, Compare comp);
Why does the std algorithm use a template for the pass function instead of the std :: function?
Why the use of threads does not use the functions of semantics and algorithms?
template <class Fn, class... Args>
explicit thread (Fn&& fn, Args&&... args);
PS: I ignore the methods used in C as function pointers.
source
share