std::unordered_map::equal_range
std::pair<iterator,iterator> equal_range( const Key& key ); | ? | (since C++11) |
---|---|---|
std::pair<const_iterator,const_iterator> equal_range( const Key& key ) const; | ? | (since C++11) |
返回包含带键的所有元素的范围。key
在集装箱里。范围由两个迭代器定义,第一个迭代器指向所需范围的第一个元素,第二个迭代器指向范围的最后一个元素。
参数
key | - | key value to compare the elements to |
---|
返回值
std::pair
包含一对迭代器,定义所需范围。如果没有这样的元素,请参阅end()
%29迭代器作为对的两个元素返回。
复杂性
与键的元素数成线性关系的平均情况key
,最坏的情况与容器的大小成线性关系。
例
二次
#include <iostream>
#include <unordered_map>
int main()
{
std::unordered_map<int,char> map = {{1,'a'},{1,'b'},{1,'d'},{2,'b'}};
auto range = map.equal_range(1);
for (auto it = range.first; it != range.second; ++it) {
std::cout << it->first << ' ' << it->second << '\n';
}
}
二次
产出:
二次
1 a
二次
另见
find | finds element with specific key (public member function) |
---|
? cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com