hash_map::equal_range (STL/CLR)

查找与指定键匹配的范围。

    cliext::pair<iterator, iterator> equal_range(key_type key);

参数


  • 要搜索的键值。

备注

成员函数返回一对迭代器 cliext::pair<iterator, iterator>( hash_map::lower_bound (STL/CLR)hash_map::upper_bound (STL/CLR)(key), (key))。 可以使用它来确定当前受控序列中与指定键匹配的元素范围。

示例

// cliext_hash_map_equal_range.cpp 
// compile with: /clr 
#include <cliext/hash_map> 
 
typedef cliext::hash_map<wchar_t, int> Myhash_map; 
typedef Myhash_map::pair_iter_iter Pairii; 
int main() 
    { 
    Myhash_map c1; 
    c1.insert(Myhash_map::make_value(L'a', 1)); 
    c1.insert(Myhash_map::make_value(L'b', 2)); 
    c1.insert(Myhash_map::make_value(L'c', 3)); 
 
// display contents " [a 1] [b 2] [c 3]" 
    for each (Myhash_map::value_type elem in c1) 
        System::Console::Write(" [{0} {1}]", elem->first, elem->second); 
    System::Console::WriteLine(); 
 
// display results of failed search 
    Pairii pair1 = c1.equal_range(L'x'); 
    System::Console::WriteLine("equal_range(L'x') empty = {0}", 
        pair1.first == pair1.second); 
 
// display results of successful search 
    pair1 = c1.equal_range(L'b'); 
    for (; pair1.first != pair1.second; ++pair1.first) 
        System::Console::Write(" [{0} {1}]", 
            pair1.first->first, pair1.first->second); 
    System::Console::WriteLine(); 
    return (0); 
    } 
 
  

要求

标头: <cliext/hash_map>

命名空间: cliext

请参见

参考

hash_map (STL/CLR)

hash_map::count (STL/CLR)

hash_map::find (STL/CLR)

hash_map::lower_bound (STL/CLR)

hash_map::upper_bound (STL/CLR)