Udostępnij za pośrednictwem


multimap::equal_range

Znajduje zakres elementów, której klucz elementu odpowiada określonej wartości.

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

Parametry

  • _Key
    Klucz argument należy porównać z elementu z Mapa wielokrotnego dopasowania, przeszukiwanych klucz sortowania.

Wartość zwracana

Para Iteratory takie, że jest pierwszym lower_bound , a drugi klucz jest upper_bound klucza.

Pierwszy iteratora parę dostępu do pr zwrócone przez funkcję Członkowskich, użyj pr. pierwszego i do nieprawidłowego iteratora dolna, użyj * (pr.pierwszy).Drugi iteratora parę dostępu do pr zwrócone przez funkcję Członkowskich, użyj pr. drugi i do nieprawidłowego iteratora górne, użyj * (pr.drugi).

Przykład

// multimap_equal_range.cpp
// compile with: /EHsc
#include <map>
#include <iostream>

int main( )
{
   using namespace std;
   typedef multimap <int, int, less<int> > IntMMap;
   IntMMap m1;
   multimap <int, int> :: const_iterator m1_RcIter;
   typedef pair <int, int> Int_Pair;

   m1.insert ( Int_Pair ( 1, 10 ) );
   m1.insert ( Int_Pair ( 2, 20 ) );
   m1.insert ( Int_Pair ( 3, 30 ) );

   pair <IntMMap::const_iterator, IntMMap::const_iterator> p1, p2;
   p1 = m1.equal_range( 2 );

   cout << "The lower bound of the element with "
        << "a key of 2 in the multimap m1 is: "
        << p1.first -> second << "." << endl;

   cout << "The upper bound of the element with "
        << "a key of 2 in the multimap m1 is: "
        << p1.second -> second << "." << endl;

   // Compare the upper_bound called directly 
   m1_RcIter = m1.upper_bound( 2 );

   cout << "A direct call of upper_bound( 2 ) gives "
        << m1_RcIter -> second << "," << endl
        << " matching the 2nd element of the pair"
        << " returned by equal_range( 2 )." << endl;

   p2 = m1.equal_range( 4 );

   // If no match is found for the key,
   // both elements of the pair return end( )
   if ( ( p2.first == m1.end( ) ) && ( p2.second == m1.end( ) ) )
      cout << "The multimap m1 doesn't have an element "
           << "with a key less than 4." << endl;
   else
      cout << "The element of multimap m1 with a key >= 40 is: "
           << p1.first -> first << "." << endl;
}
  
  
  
  

Wymagania

Nagłówek: <map>

Obszar nazw: std

Zobacz też

Informacje

multimap Class

Standardowa biblioteka szablonu