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.
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).