C++ 入门(第 5 版);第 19 章 - 算法:std::lower_bound
C++ Primer (5th edition); Ch 19 - Algorithms: std::lower_bound
本文来自C++ Primer(第5th版);第 19 章“附录:算法”:
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
- 但我认为
lower_bound
returns一个迭代器表示输入序列中第一个元素不小于val
(大于或等于val)而不是相反( “...第一个元素 val
不小于该元素”)。是书上写错了吗?
Is it a mistake in the book?
如果您信任cppreference,那么:是的,这是一个错误:
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.
或者,如果您不信任该网站,this Draft C++17 Standard有:
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
.
在 this (later) online Draft Standard 中,它是 §25.8.4.2。
本文来自C++ Primer(第5th版);第 19 章“附录:算法”:
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, orend
if no such element exists.upper_bound(beg, end, val) upper_bound(beg, end, val, comp)
Returns an iterator denoting the first element
- 但我认为
lower_bound
returns一个迭代器表示输入序列中第一个元素不小于val
(大于或等于val)而不是相反( “...第一个元素val
不小于该元素”)。是书上写错了吗?
Is it a mistake in the book?
如果您信任cppreference,那么:是的,这是一个错误:
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.
或者,如果您不信任该网站,this Draft C++17 Standard有:
28.7.3.1
lower_bound
[lower.bound]
…
2 Returns: The furthermost iteratori
in the range[first, last]
such that for every iteratorj
in the range[first, i)
the following corresponding conditions hold:*j < value
orcomp(*j, value) != false
.
在 this (later) online Draft Standard 中,它是 §25.8.4.2。