set::equal_range
描述 (Description)
它返回一个范围的边界,该范围包括容器中与val等效的所有元素。
声明 (Declaration)
以下是std :: set :: equal_range在各种C ++版本中的工作方式。
C++98
iterator upper_bound (const value_type& val) const;
C++11
iterator upper_bound (const value_type& val);
const_iterator upper_bound (const value_type& val) const;
返回值
它返回一个范围的边界,该范围包括容器中与val等效的所有元素。
异常 (Exceptions)
如果抛出异常,则容器中没有更改。
时间复杂
时间复杂度取决于对数。
例子 (Example)
以下示例显示了std :: set :: equal_range的用法。
#include <iostream>
#include <set>
int main () {
std::set<int> myset;
for (int i = 1; i <= 5; i++) myset.insert(i*10);
std::pair<std::set<int>::const_iterator,std::set<int>::const_iterator> ret;
ret = myset.equal_range(10);
std::cout << "the lower bound points to: " << *ret.first << '\n';
std::cout << "the upper bound points to: " << *ret.second << '\n';
return 0;
}
上述程序将正确编译和执行。
the lower bound points to: 10
the upper bound points to: 20