开发者

STL functions with 3-way comparison predicate

Is there any library with STL functions like std::sort(), std::binary_search(), std::lower_bound(), std::upper_bound() accepting 3-way comparison predicates (which return -1 on less, 0 on equal, 1 on great) instead of less predicate (true on less, false on equal or great) ?

Of course, th开发者_开发知识库e less predicate can be easily made out from existing 3-way predicate (like [](A a, B b) { return compare3(a,b)<0; }) but this results in extra number of calls to the predicate.


If you look at the implementation of the above algorithms, you'll see that lower/upper_bound don't do 3-way branches at all, binary_search does only in the last iteration to check equality and about sort() I don't know but I'm almost sure it doesn't do 3-way branches too. So your 'optimization' won't give you any boost. The opposite is true, your comparisons will be slower.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜