Itachi Uchiwa
Itachi Uchiwa

Reputation: 3164

C++ Primer (5th edition); Ch 19 - Algorithms: std::lower_bound

This is from C++ Primer (5th edition); Ch 19. "Appendix: algorithms":

lower_bound(beg, end, val)
lower_bound(beg, end, val, comp)

Returns an iterator denoting the first element such that val is not less than that element, or end if no such element exists.

upper_bound(beg, end, val)
upper_bound(beg, end, val, comp)

Returns an iterator denoting the first element

Upvotes: 4

Views: 110

Answers (1)

Adrian Mole
Adrian Mole

Reputation: 51845

Is it a mistake in the book?

If you trust cppreference, then: Yes, it is a mistake:

std::lower_bound

Returns an iterator pointing to the first element in the range [first, last) that is not less than (i.e. greater or equal to) value, or last if no such element is found.

Or, if you don't trust that website, this Draft C++17 Standard has:

28.7.3.1 lower_bound       [lower.bound]



2     Returns: The furthermost iterator i in the range [first, last] such that for every iterator j in the range [first, i) the following corresponding conditions hold: *j < value or comp(*j, value) != false.

In this (later) online Draft Standard, it's §25.8.4.2.

Upvotes: 2

Related Questions