C++ Set 库 - lower_bound 函数
描述
它返回一个迭代器,指向容器中不被认为在 val 之前的第一个元素。
声明
以下是 std::set::lower_bound 在各种 C++ 版本中的工作方式。
C++98
iterator lower_bound (const value_type& val) const;
C++11
iterator lower_bound (const value_type& val); const_iterator lower_bound (const value_type& val) const;
返回值
它返回一个迭代器,指向容器中不被认为在 val 之前的第一个元素。
异常
如果抛出异常,则容器中没有任何变化。
时间复杂度
时间复杂度取决于对数。
示例
以下示例显示了 std::set::lower_bound 的用法。
#include <iostream>
#include <set>
int main () {
std::set<int> myset;
std::set<int>::iterator itlow,itup;
for (int i = 1; i < 10; i++) myset.insert(i*10);
itlow = myset.lower_bound (30);
myset.erase(itlow);
std::cout << "myset contains:";
for (std::set<int>::iterator it = myset.begin(); it!=myset.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
return 0;
}
上述程序将正确编译和执行。
myset contains: 10 20 40 50 60 70 80 90

