Why distinguish between predicate and non-predicate versions for common algorithms?

The standard library distinguishes between predicate and non-predicate versions of common algorithms. For example, std::sort() looks like this:

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

Are there any problems writing the following?

 template< class RandomIt, class Compare = std::less<void>> void sort( RandomIt first, RandomIt last, Compare comp = Compare{}); 
+5
source share
1 answer

Quite a few historical reasons.

In C ++ 98/03, there were no default template arguments for function templates, so he had to use two overloads. And changing it later may violate the user code.

So, suppose we just redesign it all, if the second form is preferable?

This is what the current operating range of the Ranges TS is running on .

+8
source

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


All Articles