std::unordered_map<Key,T,Hash,KeyEqual,Allocator>::equal_range
: cppreference.com
std::pair<iterator,iterator> equal_range( const Key& key ); |
(1) | (C++11) |
std::pair<const_iterator,const_iterator> equal_range( const Key& key ) const; |
(2) | (C++11) |
template< class K > std::pair<iterator,iterator> equal_range( const K& x ); |
(3) | (C++20) |
template< class K > std::pair<const_iterator,const_iterator> equal_range( const K& x ) const; |
(4) | (C++20) |
1,2)
key 2 3,4)
x Hash::is_transparent KeyEqual::is_transparent Hash K Key KeyEqual Key | key | - | |
| x | - |
key
Run this code
#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
| () |