Udostępnij za pośrednictwem


<set>, operatory

operator!= (set)

Sprawdza, czy obiekt ustawiony po lewej stronie operatora nie jest równy ustawieniu obiektu po prawej stronie.

bool operator!=(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu set.

Prawo
Obiekt typu set.

Wartość zwracana

true jeśli zestawy nie są równe; false jeśli zestawy są równe.

Uwagi

Porównanie zestawów obiektów opiera się na porównaniu parowania między elementami. Dwa zestawy są równe, jeśli mają taką samą liczbę elementów, a ich elementy mają te same wartości. W przeciwnym razie są one nierówne.

Przykład

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

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

   if ( s1 != s2 )
      cout << "The sets s1 and s2 are not equal." << endl;
   else
      cout << "The sets s1 and s2 are equal." << endl;

   if ( s1 != s3 )
      cout << "The sets s1 and s3 are not equal." << endl;
   else
      cout << "The sets s1 and s3 are equal." << endl;
}
/* Output:
The sets s1 and s2 are not equal.
The sets s1 and s3 are equal.
*/

operator< (zestaw)

Sprawdza, czy obiekt ustawiony po lewej stronie operatora jest mniejszy niż obiekt ustawiony po prawej stronie.

bool operator<(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu set.

Prawo
Obiekt typu set.

Wartość zwracana

true jeśli zestaw po lewej stronie operatora jest ściśle mniejszy niż zestaw po prawej stronie operatora; w przeciwnym razie false.

Uwagi

Porównanie zestawów obiektów jest oparte na parowym porównywaniu ich elementów. Relacja mniejszej niż między dwoma obiektami opiera się na porównaniu pierwszej pary nierównych elementów.

Przykład

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

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 < s2 )
      cout << "The set s1 is less than the set s2." << endl;
   else
      cout << "The set s1 is not less than the set s2." << endl;

   if ( s1 < s3 )
      cout << "The set s1 is less than the set s3." << endl;
   else
      cout << "The set s1 is not less than the set s3." << endl;
}
/* Output:
The set s1 is less than the set s2.
The set s1 is not less than the set s3.
*/

operator<= (zestaw)

Sprawdza, czy obiekt ustawiony po lewej stronie operatora jest mniejszy lub równy ustawić obiekt po prawej stronie.

bool operator!<=(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu set.

Prawo
Obiekt typu set.

Wartość zwracana

true jeśli zestaw po lewej stronie operatora jest mniejszy lub równy ustawieniu po prawej stronie operatora; w przeciwnym razie false.

Uwagi

Porównanie zestawów obiektów jest oparte na parowym porównywaniu ich elementów. Relacja mniejsza niż lub równa relacji między dwoma obiektami jest oparta na porównaniu pierwszej pary nierównych elementów.

Przykład

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

int main( )
{
   using namespace std;
   set <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 <= s2 )
      cout << "Set s1 is less than or equal to the set s2." << endl;
   else
      cout << "The set s1 is greater than the set s2." << endl;

   if ( s1 <= s3 )
      cout << "Set s1 is less than or equal to the set s3." << endl;
   else
      cout << "The set s1 is greater than the set s3." << endl;

   if ( s1 <= s4 )
      cout << "Set s1 is less than or equal to the set s4." << endl;
   else
      cout << "The set s1 is greater than the set s4." << endl;
}
Set s1 is less than or equal to the set s2.
The set s1 is greater than the set s3.
Set s1 is less than or equal to the set s4.

operator== (set)

Sprawdza, czy obiekt ustawiony po lewej stronie operatora jest równy obiektowi ustawionemu po prawej stronie.

bool operator!==(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu set.

Prawo
Obiekt typu set.

Wartość zwracana

true jeśli zestaw po lewej stronie operatora jest równy ustawieniu po prawej stronie operatora; w przeciwnym razie false.

Uwagi

Porównanie zestawów obiektów jest oparte na parowym porównywaniu ich elementów. Dwa zestawy są równe, jeśli mają taką samą liczbę elementów, a ich elementy mają te same wartości. W przeciwnym razie są one nierówne.

Przykład

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

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

   if ( s1 == s2 )
      cout << "The sets s1 and s2 are equal." << endl;
   else
      cout << "The sets s1 and s2 are not equal." << endl;

   if ( s1 == s3 )
      cout << "The sets s1 and s3 are equal." << endl;
   else
      cout << "The sets s1 and s3 are not equal." << endl;
}
The sets s1 and s2 are not equal.
The sets s1 and s3 are equal.

operator> (zestaw)

Sprawdza, czy obiekt ustawiony po lewej stronie operatora jest większy niż obiekt ustawiony po prawej stronie.

bool operator>(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu set.

Prawo
Obiekt typu set.

Wartość zwracana

true jeśli zestaw po lewej stronie operatora jest większy niż zestaw po prawej stronie operatora; w przeciwnym razie false.

Uwagi

Porównanie zestawów obiektów jest oparte na parowym porównywaniu ich elementów. Relacja większa niż między dwoma obiektami jest oparta na porównaniu pierwszej pary nierównych elementów.

Przykład

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

int main( )
{
   using namespace std;
   set <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 > s2 )
      cout << "The set s1 is greater than the set s2." << endl;
   else
      cout << "The set s1 is not greater than the set s2." << endl;

   if ( s1 > s3 )
      cout << "The set s1 is greater than the set s3." << endl;
   else
      cout << "The set s1 is not greater than the set s3." << endl;
}
/* Output:
The set s1 is not greater than the set s2.
The set s1 is greater than the set s3.
*/

operator>= (zestaw)

Sprawdza, czy obiekt ustawiony po lewej stronie operatora jest większy lub równy ustawić obiekt po prawej stronie.

bool operator!>=(const set <Key, Traits, Allocator>& left, const set <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu set.

Prawo
Obiekt typu set.

Wartość zwracana

true jeśli zestaw po lewej stronie operatora jest większy lub równy ustawieniu po prawej stronie listy; w przeciwnym razie false.

Uwagi

Porównanie zestawów obiektów jest oparte na parowym porównywaniu ich elementów. Relacja większa lub równa relacji między dwoma obiektami jest oparta na porównaniu pierwszej pary nierównych elementów.

Przykład

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

int main( )
{
   using namespace std;
   set <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 >= s2 )
      cout << "Set s1 is greater than or equal to set s2." << endl;
   else
      cout << "The set s1 is less than the set s2." << endl;

   if ( s1 >= s3 )
      cout << "Set s1 is greater than or equal to set s3." << endl;
   else
      cout << "The set s1 is less than the set s3." << endl;

   if ( s1 >= s4 )
      cout << "Set s1 is greater than or equal to set s4." << endl;
   else
      cout << "The set s1 is less than the set s4." << endl;
}
The set s1 is less than the set s2.
Set s1 is greater than or equal to set s3.
Set s1 is greater than or equal to set s4.

operator!= (multiset)

Sprawdza, czy obiekt wielozestawowy po lewej stronie operatora nie jest równy obiektowi wielozestawowemu po prawej stronie.

bool operator!=(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu multiset.

Prawo
Obiekt typu multiset.

Wartość zwracana

true jeśli zestawy lub zestawy wielozestawowe nie są równe; false jeśli zestawy lub zestawy wielozestawowe są równe.

Uwagi

Porównanie obiektów wielozestawowych opiera się na porównaniu parowania między elementami. Dwa zestawy lub zestawy wielozestawowe są równe, jeśli mają taką samą liczbę elementów, a ich odpowiednie elementy mają te same wartości. W przeciwnym razie są one nierówne.

Przykład

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

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

   if ( s1 != s2 )
      cout << "The multisets s1 and s2 are not equal." << endl;
   else
      cout << "The multisets s1 and s2 are equal." << endl;

   if ( s1 != s3 )
      cout << "The multisets s1 and s3 are not equal." << endl;
   else
      cout << "The multisets s1 and s3 are equal." << endl;
}
The multisets s1 and s2 are not equal.
The multisets s1 and s3 are equal.

operator< (multiset)

Sprawdza, czy obiekt wielozestawowy po lewej stronie operatora jest mniejszy niż obiekt wielozestawowy po prawej stronie.

bool operator<(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu multiset.

Prawo
Obiekt typu multiset.

Wartość zwracana

true jeśli wielozbiór po lewej stronie operatora jest ściśle mniejszy niż wielozestaw po prawej stronie operatora; w przeciwnym razie false.

Uwagi

Porównanie obiektów wielozestawowych opiera się na parowym porównywaniu ich elementów. Relacja mniejszej niż między dwoma obiektami opiera się na porównaniu pierwszej pary nierównych elementów.

Przykład

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

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 < s2 )
      cout << "The multiset s1 is less than "
           << "the multiset s2." << endl;
   else
      cout << "The multiset s1 is not less than "
           << "the multiset s2." << endl;

   if ( s1 < s3 )
      cout << "The multiset s1 is less than "
           << "the multiset s3." << endl;
   else
      cout << "The multiset s1 is not less than "
           << "the multiset s3." << endl;
}
The multiset s1 is less than the multiset s2.
The multiset s1 is not less than the multiset s3.

operator<= (multiset)

Sprawdza, czy obiekt wielozestawowy po lewej stronie operatora jest mniejszy lub równy obiektowi wielozestawowemu po prawej stronie.

bool operator!<=(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu multiset.

Prawo
Obiekt typu multiset.

Wartość zwracana

true jeśli wielozestaw po lewej stronie operatora jest mniejszy lub równy wielozestawowi po prawej stronie operatora; w przeciwnym razie false.

Uwagi

Porównanie obiektów wielozestawowych opiera się na parowym porównywaniu ich elementów. Relacja mniejsza niż lub równa relacji między dwoma obiektami jest oparta na porównaniu pierwszej pary nierównych elementów.

Przykład

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

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 <= s2 )
      cout << "The multiset s1 is less than "
           << "or equal to the multiset s2." << endl;
   else
      cout << "The multiset s1 is greater than "
           << "the multiset s2." << endl;

   if ( s1 <= s3 )
      cout << "The multiset s1 is less than "
           << "or equal to the multiset s3." << endl;
   else
      cout << "The multiset s1 is greater than "
           << "the multiset s3." << endl;

   if ( s1 <= s4 )
      cout << "The multiset s1 is less than "
           << "or equal to the multiset s4." << endl;
   else
      cout << "The multiset s1 is greater than "
           << "the multiset s4." << endl;
}
The multiset s1 is less than or equal to the multiset s2.
The multiset s1 is greater than the multiset s3.
The multiset s1 is less than or equal to the multiset s4.

operator== (multiset)

Sprawdza, czy obiekt wielozestawowy po lewej stronie operatora jest równy obiektowi wielozestawowemu po prawej stronie.

bool operator!==(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu multiset.

Prawo
Obiekt typu multiset.

Wartość zwracana

true jeśli wielozbiór po lewej stronie operatora jest równy wielozestawowi po prawej stronie operatora; w przeciwnym razie false.

Uwagi

Porównanie obiektów wielozestawowych opiera się na parowym porównywaniu ich elementów. Dwa zestawy lub zestawy wielozestawowe są równe, jeśli mają taką samą liczbę elementów, a ich odpowiednie elementy mają te same wartości. W przeciwnym razie są one nierówne.

Przykład

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

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i );
   }

   if ( s1 == s2 )
      cout << "The multisets s1 and s2 are equal." << endl;
   else
      cout << "The multisets s1 and s2 are not equal." << endl;

   if ( s1 == s3 )
      cout << "The multisets s1 and s3 are equal." << endl;
   else
      cout << "The multisets s1 and s3 are not equal." << endl;
}
The multisets s1 and s2 are not equal.
The multisets s1 and s3 are equal.

operator> (multiset)

Sprawdza, czy obiekt wielozestawowy po lewej stronie operatora jest większy niż obiekt wielozestawowy po prawej stronie.

bool operator>(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu multiset.

Prawo
Obiekt typu multiset.

Wartość zwracana

true jeśli wielozestaw po lewej stronie operatora jest większy niż wielozestaw po prawej stronie operatora; w przeciwnym razie false.

Uwagi

Porównanie obiektów wielozestawowych opiera się na parowym porównywaniu ich elementów. Relacja większa niż między dwoma obiektami jest oparta na porównaniu pierwszej pary nierównych elementów.

Przykład

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

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
   }

   if ( s1 > s2 )
      cout << "The multiset s1 is greater than "
           << "the multiset s2." << endl;
   else
      cout << "The multiset s1 is not greater "
           << "than the multiset s2." << endl;

   if ( s1 > s3 )
      cout << "The multiset s1 is greater than "
           << "the multiset s3." << endl;
   else
      cout << "The multiset s1 is not greater than "
           << "the multiset s3." << endl;
}
The multiset s1 is not greater than the multiset s2.
The multiset s1 is greater than the multiset s3.

operator>= (multiset)

Sprawdza, czy obiekt wielozestawowy po lewej stronie operatora jest większy lub równy obiektowi wielozestawowemu po prawej stronie.

bool operator!>=(const multiset <Key, Traits, Allocator>& left, const multiset <Key, Traits, Allocator>& right);

Parametry

Lewej
Obiekt typu multiset.

Prawo
Obiekt typu multiset.

Wartość zwracana

true jeśli wielozestaw po lewej stronie operatora jest większy lub równy wielozestawowi po prawej stronie listy; w przeciwnym razie false.

Uwagi

Porównanie obiektów wielozestawowych opiera się na parowym porównywaniu ich elementów. Relacja większa lub równa relacji między dwoma obiektami jest oparta na porównaniu pierwszej pary nierównych elementów.

Przykład

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

int main( )
{
   using namespace std;
   multiset <int> s1, s2, s3, s4;
   int i;

   for ( i = 0 ; i < 3 ; i++ )
   {
      s1.insert ( i );
      s2.insert ( i * i );
      s3.insert ( i - 1 );
      s4.insert ( i );
   }

   if ( s1 >= s2 )
      cout << "The multiset s1 is greater than "
           << "or equal to the multiset s2." << endl;
   else
      cout << "The multiset s1 is less than "
           << "the multiset s2." << endl;

   if ( s1 >= s3 )
      cout << "The multiset s1 is greater than "
           << "or equal to the multiset s3." << endl;
   else
      cout << "The multiset s1 is less than "
           << "the multiset s3." << endl;

   if ( s1 >= s4 )
      cout << "The multiset s1 is greater than "
           << "or equal to the multiset s4." << endl;
   else
      cout << "The multiset s1 is less than "
           << "the multiset s4." << endl;
}
The multiset s1 is less than the multiset s2.
The multiset s1 is greater than or equal to the multiset s3.
The multiset s1 is greater than or equal to the multiset s4.