Udostępnij przez


<map>, operatory

operator!=

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

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

Parametry

Lewy
Obiekt typu map.

Prawy
Obiekt typu map.

Wartość zwracana

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

Uwagi

Porównanie obiektów mapy jest oparte na parowym porównywaniu ich elementów. Dwie mapy 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

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

int main( )
{
   using namespace std;
   map <int, int> m1, m2, m3;
   int i;
   typedef pair <int, int> Int_Pair;

   for ( i = 0 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i ) );
   }

   if ( m1 != m2 )
      cout << "The maps m1 and m2 are not equal." << endl;
   else
      cout << "The maps m1 and m2 are equal." << endl;

   if ( m1 != m3 )
      cout << "The maps m1 and m3 are not equal." << endl;
   else
      cout << "The maps m1 and m3 are equal." << endl;
}
The maps m1 and m2 are not equal.
The maps m1 and m3 are equal.

operator<

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

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

Parametry

Lewy
Obiekt typu map.

Prawy
Obiekt typu map.

Wartość zwracana

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

Uwagi

Porównanie obiektów mapy 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

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

int main( )
{
   using namespace std;
   map<int, int> m1, m2, m3;
   int i;
   typedef pair<int, int> Int_Pair;

   for ( i = 1 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i - 1 ) );
   }

   if ( m1 < m2 )
      cout << "The map m1 is less than the map m2." << endl;
   else
      cout << "The map m1 is not less than the map m2." << endl;

   if ( m1 < m3 )
      cout << "The map m1 is less than the map m3." << endl;
   else
      cout << "The map m1 is not less than the map m3." << endl;
}
The map m1 is less than the map m2.
The map m1 is not less than the map m3.

operator<=

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

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

Parametry

Lewy
Obiekt typu map.

Prawy
Obiekt typu map.

Wartość zwracana

true jeśli mapa po lewej stronie operatora jest mniejsza lub równa mapie po prawej stronie operatora; w przeciwnym razie false.

Przykład

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

int main( )
{
   using namespace std;
   map <int, int> m1, m2, m3, m4;
   int i;
   typedef pair <int, int> Int_Pair;

   for ( i = 1 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i - 1 ) );
      m4.insert ( Int_Pair ( i, i ) );
   }

   if ( m1 <= m2 )
      cout << "The map m1 is less than or equal to the map m2." << endl;
   else
      cout << "The map m1 is greater than the map m2." << endl;

   if ( m1 <= m3 )
      cout << "The map m1 is less than or equal to the map m3." << endl;
   else
      cout << "The map m1 is greater than the map m3." << endl;

   if ( m1 <= m4 )
      cout << "The map m1 is less than or equal to the map m4." << endl;
   else
      cout << "The map m1 is greater than the map m4." << endl;
}
The map m1 is less than or equal to the map m2.
The map m1 is greater than the map m3.
The map m1 is less than or equal to the map m4.

operator==

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

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

Parametry

Lewy
Obiekt typu map.

Prawy
Obiekt typu map.

Wartość zwracana

true jeśli mapa po lewej stronie operatora jest równa mapie po prawej stronie operatora; w przeciwnym razie false.

Uwagi

Porównanie obiektów mapy jest oparte na parowym porównywaniu ich elementów. Dwie mapy 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

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

int main( )
{
   using namespace std;
   map < int, int > m1, m2, m3;
   int i;
   typedef pair < int, int > Int_Pair;

   for ( i = 0 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i ) );
   }

   if ( m1 == m2 )
      cout << "The maps m1 and m2 are equal." << endl;
   else
      cout << "The maps m1 and m2 are not equal." << endl;

   if ( m1 == m3 )
      cout << "The maps m1 and m3 are equal." << endl;
   else
      cout << "The maps m1 and m3 are not equal." << endl;
}
The maps m1 and m2 are not equal.
The maps m1 and m3 are equal.

operator>

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

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

Parametry

Lewy
Obiekt typu map.

Prawy
Obiekt typu map.

Wartość zwracana

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

Uwagi

Porównanie obiektów mapy 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

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

int main( )
{
   using namespace std;
   map < int, int > m1, m2, m3;
   int i;
   typedef pair < int, int > Int_Pair;

   for ( i = 0 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i - 1 ) );
   }

   if ( m1 > m2 )
      cout << "The map m1 is greater than the map m2." << endl;
   else
      cout << "The map m1 is not greater than the map m2." << endl;

   if ( m1 > m3 )
      cout << "The map m1 is greater than the map m3." << endl;
   else
      cout << "The map m1 is not greater than the map m3." << endl;
}
/* Output:
The map m1 is not greater than the map m2.
The map m1 is greater than the map m3.
*/

operator>=

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

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

Parametry

Lewy
Obiekt typu map.

Prawy
Obiekt typu map.

Wartość zwracana

true jeśli mapa po lewej stronie operatora jest większa lub równa mapie po prawej stronie listy; w przeciwnym razie false.

Przykład

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

int main( )
{
   using namespace std;
   map < int, int > m1, m2, m3, m4;
   int i;
   typedef pair < int, int > Int_Pair;

   for ( i = 1 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i - 1 ) );
      m4.insert ( Int_Pair ( i, i ) );
   }

   if ( m1 >= m2 )
      cout << "Map m1 is greater than or equal to map m2." << endl;
   else
      cout << "The map m1 is less than the map m2." << endl;

   if ( m1 >= m3 )
      cout << "Map m1 is greater than or equal to map m3." << endl;
   else
      cout << "The map m1 is less than the map m3." << endl;

   if ( m1 >= m4 )
      cout << "Map m1 is greater than or equal to map m4." << endl;
   else
      cout << "The map m1 is less than the map m4." << endl;
}
The map m1 is less than the map m2.
Map m1 is greater than or equal to map m3.
Map m1 is greater than or equal to map m4.

operator!= (multimap)

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

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

Parametry

Lewy
Obiekt typu multimap.

Prawy
Obiekt typu multimap.

Wartość zwracana

true jeśli mapy wielomapowe nie są równe; false jeśli multimapy są równe.

Uwagi

Porównanie obiektów wielomapowych opiera się na parowym porównaniu ich elementów. Dwie mapy wielomapowe 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

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

int main( )
{
   using namespace std;
   multimap <int, int> m1, m2, m3;
   int i;
   typedef pair <int, int> Int_Pair;

   for ( i = 0 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i ) );
   }

   if ( m1 != m2 )
      cout << "The multimaps m1 and m2 are not equal." << endl;
   else
      cout << "The multimaps m1 and m2 are equal." << endl;

   if ( m1 != m3 )
      cout << "The multimaps m1 and m3 are not equal." << endl;
   else
      cout << "The multimaps m1 and m3 are equal." << endl;
}
The multimaps m1 and m2 are not equal.
The multimaps m1 and m3 are equal.

operator< (mapa wielomapowa)

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

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

Parametry

Lewy
Obiekt typu multimap.

Prawy
Obiekt typu multimap.

Wartość zwracana

true jeśli multimapa po lewej stronie operatora jest ściśle mniejsza niż mapa wielokrotna po prawej stronie operatora; w przeciwnym razie false.

Uwagi

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

Przykład

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

int main( )
{
   using namespace std;
   multimap < int, int > m1, m2, m3;
   int i;
   typedef pair < int, int > Int_Pair;

   for ( i = 1 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i - 1 ) );
   }

   if ( m1 < m2 )
      cout << "The multimap m1 is less than the multimap m2." << endl;
   else
      cout << "The multimap m1 is not less than the multimap m2." << endl;

   if ( m1 < m3 )
      cout << "The multimap m1 is less than the multimap m3." << endl;
   else
      cout << "The multimap m1 is not less than the multimap m3." << endl;
}
The multimap m1 is less than the multimap m2.
The multimap m1 is not less than the multimap m3.

operator<= (mapa wielomapowa)

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

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

Parametry

Lewy
Obiekt typu multimap.

Prawy
Obiekt typu multimap.

Wartość zwracana

true jeśli multimapa po lewej stronie operatora jest mniejsza lub równa wielomapie po prawej stronie operatora; w przeciwnym razie false.

Przykład

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

int main( )
{
   using namespace std;
   multimap <int, int> m1, m2, m3, m4;
   int i;
   typedef pair <int, int> Int_Pair;

   for ( i = 1 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i - 1 ) );
      m4.insert ( Int_Pair ( i, i ) );
   }

   if ( m1 <= m2 )
      cout << "m1 is less than or equal to m2" << endl;
   else
      cout << "m1 is greater than m2" << endl;

   if ( m1 <= m3 )
      cout << "m1 is less than or equal to m3" << endl;
   else
      cout << "m1 is greater than m3" << endl;

   if ( m1 <= m4 )
      cout << "m1 is less than or equal to m4" << endl;
   else
      cout << "m1 is greater than m4" << endl;
}
m1 is less than or equal to m2
m1 is greater than m3
m1 is less than or equal to m4

operator== (multimap)

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

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

Parametry

Lewy
Obiekt typu multimap.

Prawy
Obiekt typu multimap.

Wartość zwracana

true jeśli multimapa po lewej stronie operatora jest równa wielomapie po prawej stronie operatora; w przeciwnym razie false.

Uwagi

Porównanie obiektów wielomapowych opiera się na parowym porównaniu ich elementów. Dwie mapy wielomapowe 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

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

int main( )
{
   using namespace std;
   multimap<int, int> m1, m2, m3;
   int i;
   typedef pair<int, int> Int_Pair;

   for (i = 0; i < 3; i++)
   {
      m1.insert(Int_Pair(i, i));
      m2.insert(Int_Pair(i, i*i));
      m3.insert(Int_Pair(i, i));
   }

   if ( m1 == m2 )
      cout << "m1 and m2 are equal" << endl;
   else
      cout << "m1 and m2 are not equal" << endl;

   if ( m1 == m3 )
      cout << "m1 and m3 are equal" << endl;
   else
      cout << "m1 and m3 are not equal" << endl;
}
m1 and m2 are not equal
m1 and m3 are equal

operator> (mapa wielomapowa)

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

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

Parametry

Lewy
Obiekt typu multimap.

Prawy
Obiekt typu multimap.

Wartość zwracana

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

Uwagi

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

Przykład

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

int main( )
{
   using namespace std;
   multimap < int, int > m1, m2, m3;
   int i;
   typedef pair < int, int > Int_Pair;

   for ( i = 0 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i - 1 ) );
   }

   if ( m1 > m2 )
      cout << "The multimap m1 is greater than the multimap m2." << endl;
   else
      cout << "Multimap m1 is not greater than multimap m2." << endl;

   if ( m1 > m3 )
      cout << "The multimap m1 is greater than the multimap m3." << endl;
   else
      cout << "The multimap m1 is not greater than the multimap m3." << endl;
}
Multimap m1 is not greater than multimap m2.
The multimap m1 is greater than the multimap m3.

operator>= (mapa wielomapowa)

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

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

Parametry

Lewy
Obiekt typu multimap.

Prawy
Obiekt typu multimap.

Wartość zwracana

true jeśli multimapa po lewej stronie operatora jest większa lub równa wielomapie po prawej stronie listy; w przeciwnym razie false.

Przykład

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

int main( )
{
   using namespace std;
   multimap < int, int > m1, m2, m3, m4;
   int i;
   typedef pair < int, int > Int_Pair;

   for ( i = 1 ; i < 3 ; i++ )
   {
      m1.insert ( Int_Pair ( i, i ) );
      m2.insert ( Int_Pair ( i, i * i ) );
      m3.insert ( Int_Pair ( i, i - 1 ) );
      m4.insert ( Int_Pair ( i, i ) );
   }

   if ( m1 >= m2 )
      cout << "The multimap m1 is greater than or equal to the multimap m2." << endl;
   else
      cout << "The multimap m1 is less than the multimap m2." << endl;

   if ( m1 >= m3 )
      cout << "The multimap m1 is greater than or equal to the multimap m3." << endl;
   else
      cout << "The multimap m1 is less than the multimap m3." << endl;

   if ( m1 >= m4 )
      cout << "The multimap m1 is greater than or equal to the multimap m4." << endl;
   else
      cout << "The multimap m1 is less than the multimap m4." << endl;
}
The multimap m1 is less than the multimap m2.
The multimap m1 is greater than or equal to the multimap m3.
The multimap m1 is greater than or equal to the multimap m4.