Compartilhar via


multiset::equal_range

Retorna um par de iteradores respectivamente para o primeiro elemento em um multiset com uma chave que é maior do que uma chave especificada e para o primeiro elemento no multiset com uma chave para que é igual ou maior do que a chave.

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

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

Parâmetros

  • _Key
    A chave de argumento a ser comparado com a chave de tipo de um elemento de multiset que está sendo pesquisado.

Valor de retorno

Um par de iteradores para que o primeiro é lower_bound de chave e da segunda é upper_bound de chave.

Para acessar o primeiro iterador de um par pr retornado pela função de membro, use pr.first, e para desreferenciar o iterador do limite inferior, uso (*pr.first).Para acessar o segundo iterador de um par pr retornado pela função de membro, use pr.second, e para desreferenciar o iterador o limite superior, uso (*pr.second).

Exemplo

// multiset_equal_range.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;    
   typedef multiset<int, less<int> > IntSet;
   IntSet ms1;
   multiset <int> :: const_iterator ms1_RcIter;
   
   ms1.insert( 10 );
   ms1.insert( 20 );
   ms1.insert( 30 );

   pair <IntSet::const_iterator, IntSet::const_iterator> p1, p2;
   p1 = ms1.equal_range( 20 );

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

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

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

   p2 = ms1.equal_range( 40 );

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

Requisitos

Cabeçalho: <set>

namespace: STD

Consulte também

Referência

multiset Class

Standard Template Library