简体   繁体   中英

std::lower_bound() implementation

I am curious why std::lower_bound() asks for passing by value for the compare function rather than by reference?

Passing by value means a copy is needed, slowing things down; especially, if someone passes in a "big" compare function object.

Many if not most comparison objects are stateless and take almost no size (they can't have zero size though). Passing a reference could actually be more expensive than passing a stateless predicate by value (especially if the compiler is able to totally elide the copy).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM