C++ 入门(第 5 版);第 19 章 - 算法:std::lower_bound

标签 c++ algorithm language-lawyer lower-bound

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

    相关文章:

    c++ - 有关使用好友功能查找姓名的问题

    c++ - Qt 读取串行数据 - 工作代码但需要更可靠

    c++ - 如何在 OSX 上获取 "codesigned"gdb?

    algorithm - 从图中消除循环流

    c++ - FFT计算从入门到算法

    c++ - 类模板参数推导和默认模板参数

    c++ - C++ 标准是否保证未使用的私有(private)字段会影响 sizeof?

    c++ - 复制构造函数和赋值运算符都被调用

    c++ - 在 C++ 中以图形方式为图形绘制顶点

    algorithm - 如何根据项目的重量将项目列表分成相等的分区?