std::
unordered_multiset::equal_range
公众成员函数 <unordered_set>
pair<iterator,iterator>
equal_range ( const key_type& k );
pair<const_iterator,const_iterator>
equal_range ( const key_type& k ) const;
|
获取具有特定键的元素范围
返回一个范围的边界,该范围包括所有比较值等于k的元素。
如果k不匹配容器中的任何元素,则返回的范围的下界和上界都是
end。
☲ 参数
-
K
-
要比较的值。
成员类型key_type是容器中元素的类型。在unordered_multiset容器中,
它与value_type相同,定义为类的第一个模板形参(Key)的别名。
☉ 返回值
该函数返回一个
pair,其成员
pair::first是范围的下界,
pair::second是范围的上界。
范围内的元素是位于这两个迭代器之间的元素,包括
pair::first,不包括
pair::second。
成员类型
iterator和
const_iterator是前向迭代器类型。两者都可以是相同迭代器类型的别名。
☣ 示例
// unordered_multiset::equal_range
#include <iostream>
#include <string>
#include <unordered_set>
int main ()
{
std::unordered_multiset<std::string> myums =
{"cow","pig","pig","chicken","pig","chicken"};
auto myrange = myums.equal_range("pig");
std::cout << "These pigs were found:";
while ( myrange.first != myrange.second ) {
std::cout << " " << *myrange.first++;
}
std::cout << std::endl;
return 0;
}
|
输出:
These pigs were found: pig pig pig
✥ 复杂度
平均情况下:常数。
最坏情况:容器大小呈线性。
☣ 迭代器的有效性
不变.
🍄 另请参阅
unordered_multiset::find |
获取元素迭代器(公众成员函数) |
unordered_multiset::count |
具有特定值的元素数量(公众成员函数) |