set::lower_bound

Restituisce un iteratore il primo elemento in un set con una chiave a cui è uguale o superiore alla chiave specificata.

const_iterator lower_bound(
   const Key& _Key
) const;
iterator lower_bound(
   const Key& _Key
);

Parametri

  • _Key
    La chiave dell'argomento da confrontare con la chiave di ordinamento di un elemento dal set presente.

Valore restituito

Un iteratore o const_iterator destinato alla posizione di un elemento in un set che con una chiave a uguale a o maggiore della chiave dell'argomento o a cui è destinato alla posizione che è l'ultimo elemento a set se non viene rilevata alcuna corrispondenza della chiave.

Esempio

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

int main( )
{
   using namespace std;
   set <int> s1;
   set <int> :: const_iterator s1_AcIter, s1_RcIter;
   
   s1.insert( 10 );
   s1.insert( 20 );
   s1.insert( 30 );

   s1_RcIter = s1.lower_bound( 20 );
   cout << "The element of set s1 with a key of 20 is: "
        << *s1_RcIter << "." << endl;

   s1_RcIter = s1.lower_bound( 40 );

   // If no match is found for the key, end( ) is returned
   if ( s1_RcIter == s1.end( ) )
      cout << "The set s1 doesn't have an element "
           << "with a key of 40." << endl;
   else
      cout << "The element of set s1 with a key of 40 is: "
           << *s1_RcIter << "." << endl;

   // The element at a specific location in the set can be found 
   // by using a dereferenced iterator that addresses the location
   s1_AcIter = s1.end( );
   s1_AcIter--;
   s1_RcIter = s1.lower_bound( *s1_AcIter );
   cout << "The element of s1 with a key matching "
        << "that of the last element is: "
        << *s1_RcIter << "." << endl;
}
  
  
  

Requisiti

intestazione: <set>

Spazio dei nomi: deviazione standard

Vedere anche

Riferimenti

set Class

set::lower_bound, set::upper_bound, e set::equal_range

Libreria di modelli standard