C++ Multimap 库 - lower_bound() 函数
描述
C++ 函数 std::multimap::lower_bound() 返回一个迭代器,它指向不小于键 k 的第一个元素。
声明
以下是 std::multimap::lower_bound() 函数形式 std::map 头的声明。
C++98
iterator lower_bound (const key_type& k); const_iterator lower_bound (const key_type& k) const;
参数
k − 要搜索的关键词。
返回值
如果 object 是常量限定的,则方法返回一个常量迭代器,否则返回非常量迭代器。
异常
如果抛出异常,对容器没有影响。
时间复杂度
Logarithmic i.e. O(log n)
示例
以下示例显示了 std::multimap::lower_bound() 函数的用法。
#include <iostream>
#include <map>
using namespace std;
int main(void) {
/* Multimap with duplicates */
multimap<char, int> m {
{'a', 1},
{'a', 2},
{'b', 3},
{'c', 4},
{'d', 5}
};
auto it = m.lower_bound('a');
cout << "Lower bound is" << endl;
cout << it->first << " = " << it->second << endl;
return 0;
}
让我们编译并运行上面的程序,这将产生以下结果 −
Lower bound is a = 1

