Udostępnij za pośrednictwem


hash_set::equal_range

[!UWAGA]

Ten interfejs API jest nieaktualny.Alternatywą jest unordered_set — Klasa.

Zwraca parę Iteratory odpowiednio do pierwszego elementu w polu Mieszanie, ustawianie za pomocą klucza, która jest równa określony klucz i do pierwszego elementu mieszania ustawić przy użyciu klucza, która jest większa niż klucz.

pair <const_iterator, const_iterator> equal_range ( 
   const Key& _Key 
) const; 
pair <iterator, iterator> equal_range ( 
   const Key& _Key 
);

Parametry

  • _Key
    Klucz argument ma być porównywana z kluczem sortowania elementu z hash_set są przeszukiwane.

Wartość zwracana

Para Iteratory, gdzie pierwsza z nich to lower_bound z kluczem, a drugi jest upper_bound klucza.

Aby uzyskać dostęp do pierwszego sterująca pr pary zwróconych przez funkcję członka, należy użyć pr. pierwszyi do cofnięcia odwołania sterująca dolną granicą, użyj * (pr.pierwszy).Drugi sterująca parę dostępu do pr zwrócone przez funkcję członka, użyj pr. drugii do cofnięcia odwołania sterująca górna granica, użyj * (pr.drugi).

Uwagi

W Visual C++ .NET 2003, elementy członkowskie plików nagłówka <hash_map> i <hash_set> nie są już w przestrzeni nazw std, ale raczej zostały przeniesione do przestrzeni nazw stdext.Zobacz Przestrzeń nazw stdext, aby uzyskać więcej informacji.

Przykład

// hash_set_equal_range.cpp
// compile with: /EHsc
#include <hash_set>
#include <iostream>

int main( )
{
   using namespace std; 
   using namespace stdext;
   typedef hash_set<int> IntHSet;
   IntHSet hs1;
   hash_set <int> :: const_iterator hs1_RcIter;
   
   hs1.insert( 10 );
   hs1.insert( 20 );
   hs1.insert( 30 );

   pair <IntHSet::const_iterator, IntHSet::const_iterator> p1, p2;
   p1 = hs1.equal_range( 20 );

   cout << "The upper bound of the element with "
        << "a key of 20 in the hash_set hs1 is: "
        << *(p1.second) << "." << endl;

   cout << "The lower bound of the element with "
        << "a key of 20 in the hash_set hs1 is: "
        << *(p1.first) << "." << endl;

   // Compare the upper_bound called directly 
   hs1_RcIter = hs1.upper_bound( 20 );
   cout << "A direct call of upper_bound( 20 ) gives "
        << *hs1_RcIter << "," << endl
        << "matching the 2nd element of the pair"
        << " returned by equal_range( 20 )." << endl;

   p2 = hs1.equal_range( 40 );

   // If no match is found for the key,
   // both elements of the pair return end( )
   if ( ( p2.first == hs1.end( ) ) && ( p2.second == hs1.end( ) ) )
      cout << "The hash_set hs1 doesn't have an element "
           << "with a key greater than or equal to 40." << endl;
   else
      cout << "The element of hash_set hs1 with a key >= 40 is: "
           << *(p1.first) << "." << endl;
}
  

Wymagania

Nagłówek: <hash_set>

Przestrzeń nazw: stdext

Zobacz też

Informacje

hash_set — Klasa

Standardowa biblioteka szablonów