这是来自 C++ Primer(第 5 版);第 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
返回一个迭代器,表示输入序列中不小于 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 节 .
关于C++ 入门(第 5 版);第 19 章 - 算法:std::lower_bound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69155417/