STL functions with 3-position comparison predicate

Is there a library with STL functions such as std::sort() , std::binary_search() , std::lower_bound() , std::upper_bound() that accepts three-dimensional comparison predicates (which return -1 by a smaller, 0 on equal, 1 on large) instead of less predicate (true on less, false on equal or large)?

Of course, the fewer predicates can be easily made from an existing three-way predicate (for example, [](A a, B b) { return compare3(a,b)<0; } ), but this leads to an additional number of predicate calls.

+4
source share
1 answer

If you look at the implementation of the above algorithms, you will see that lower / upper_bound does not execute tripartite branches at all, binary_search does only at the last iteration to check equality and about sort () I do not know, but I'm almost sure that it does not work with either 3 branches. Therefore, your "optimization" will not give you any increase. The opposite is true, your comparisons will be slower.

+4
source

All Articles