Using the comparison function in the stl container

Why can I do this:

stable_sort(it1, it2, binary_function);

but not this:

priority_queue<type, vector<type>, binary_function> pq;

Why can I use the function in the first case, but I need an object in the second?

+3
source share
2 answers

If you look at the link to std::stable_sort, you will see that the one provided binary_functionmust be a functional object as well ... There is no difference between them, except that in the second case there is no proper "cast" or conversion made from the function to the corresponding functional object.

, , *sort , , , *sort, . , ( ), , -. , , , . , ++ a std::function, "" .

, ...

+1

priority_queue , , binary_function - .

+3

Source: https://habr.com/ru/post/1780435/


All Articles