577. upper_bound(first, last, ...) cannot return last

Section: 26.8.4.3 [upper.bound] Status: CD1 Submitter: Seungbeom Kim Opened: 2006-05-03 Last modified: 2016-01-28

Priority: Not Prioritized

View all issues with CD1 status.

Discussion:

ISO/IEC 14882:2003 says:

25.3.3.2 upper_bound

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

From the description above, upper_bound cannot return last, since it's not in the interval [first, last). This seems to be a typo, because if value is greater than or equal to any other values in the range, or if the range is empty, returning last seems to be the intended behaviour. The corresponding interval for lower_bound is also [first, last].

Proposed resolution:

Change [lib.upper.bound]:

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