描述
它返回一個指向容器中第一個元素的迭代器,該元素不被認為是在 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
相關用法
- C++ set lower_bound()用法及代碼示例
- C++ set rbegin()用法及代碼示例
- C++ set upper_bound()用法及代碼示例
- C++ set crbegin用法及代碼示例
- C++ set size用法及代碼示例
- C++ set emplace用法及代碼示例
- C++ set swap()用法及代碼示例
- C++ set size()用法及代碼示例
- C++ set begin用法及代碼示例
- C++ set end用法及代碼示例
- C++ set erase()用法及代碼示例
- C++ set find用法及代碼示例
- C++ set find()用法及代碼示例
- C++ set count用法及代碼示例
- C++ set end()用法及代碼示例
- C++ set cbegin()用法及代碼示例
- C++ set key_comp()用法及代碼示例
- C++ set equal_range()用法及代碼示例
- C++ set emplace_hint用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Set Library - lower_bound Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。