<utility>
, operatory
Uwaga
Operatory używające polecenia Type&
są uwzględniane w obszarze namespace rel_ops
.
operator!=
Sprawdza, czy obiekt pary po lewej stronie operatora nie jest równy obiektowi pary po prawej stronie.
template <class Type>
constexpr bool operator!=(const Type& left, const Type& right);
template <class T, class U>
constexpr bool operator!=(const pair<T, U>& left, const pair<T, U>& right);
Parametry
Lewej
Obiekt typu pair
.
Prawo
Obiekt typu pair
.
Wartość zwracana
true
jeśli pary nie są równe; false
jeśli pary są równe.
Uwagi
Jedna para jest równa innej parze, jeśli każda z ich odpowiednich elementów jest równa. Dwie pary są nierówne, jeśli pierwszy lub drugi element jednej pary nie jest równy odpowiedniemu elementowi drugiej pary.
Przykład
// utility_op_ne.cpp
// compile with: /EHsc
#include <utility>
#include <iomanip>
#include <iostream>
int main( )
{
using namespace std;
pair <int, double> p1, p2, p3;
p1 = make_pair ( 10, 1.11e-1 );
p2 = make_pair ( 1000, 1.11e-3 );
p3 = make_pair ( 10, 1.11e-1 );
cout.precision ( 3 );
cout << "The pair p1 is: ( " << p1.first << ", "
<< p1.second << " )." << endl;
cout << "The pair p2 is: ( " << p2.first << ", "
<< p2.second << " )." << endl;
cout << "The pair p3 is: ( " << p3.first << ", "
<< p3.second << " )." << endl << endl;
if ( p1 != p2 )
cout << "The pairs p1 and p2 are not equal." << endl;
else
cout << "The pairs p1 and p2 are equal." << endl;
if ( p1 != p3 )
cout << "The pairs p1 and p3 are not equal." << endl;
else
cout << "The pairs p1 and p3 are equal." << endl;
}
The pair p1 is: ( 10, 0.111 ).
The pair p2 is: ( 1000, 0.00111 ).
The pair p3 is: ( 10, 0.111 ).
The pairs p1 and p2 are not equal.
The pairs p1 and p3 are equal.
operator==
Sprawdza, czy obiekt pary po lewej stronie operatora jest równy obiektowi pary po prawej stronie.
template <class T, class U>
constexpr bool operator==(const pair<T, U>& left, const pair<T, U>& right);
Parametry
Lewej
Obiekt typu pair
.
Prawo
Obiekt typu pair
.
Wartość zwracana
true
jeśli pary są równe; false
pair
jeśli s nie są równe.
Uwagi
Jedna para jest równa innej parze, jeśli każda z ich odpowiednich elementów jest równa. Funkcja zwraca left
wartość . pierwszy == right
. first &&& left
. drugi == right
. drugi. Dwie pary są nierówne, jeśli pierwszy lub drugi element jednej pary nie jest równy odpowiedniemu elementowi drugiej pary.
Przykład
// utility_op_eq.cpp
// compile with: /EHsc
#include <utility>
#include <iomanip>
#include <iostream>
int main( )
{
using namespace std;
pair <int, double> p1, p2, p3;
p1 = make_pair ( 10, 1.11e-1 );
p2 = make_pair ( 1000, 1.11e-3 );
p3 = make_pair ( 10, 1.11e-1 );
cout.precision ( 3 );
cout << "The pair p1 is: ( " << p1.first << ", "
<< p1.second << " )." << endl;
cout << "The pair p2 is: ( " << p2.first << ", "
<< p2.second << " )." << endl;
cout << "The pair p3 is: ( " << p3.first << ", "
<< p3.second << " )." << endl << endl;
if ( p1 == p2 )
cout << "The pairs p1 and p2 are equal." << endl;
else
cout << "The pairs p1 and p2 are not equal." << endl;
if ( p1 == p3 )
cout << "The pairs p1 and p3 are equal." << endl;
else
cout << "The pairs p1 and p3 are not equal." << endl;
}
operator<
Sprawdza, czy obiekt pary po lewej stronie operatora jest mniejszy niż obiekt pary po prawej stronie.
template <class T, class U>
constexpr bool operator<(const pair<T, U>& left, const pair<T, U>& right);
Parametry
Lewej
Obiekt typu pair
po lewej stronie operatora.
Prawo
Obiekt typu pair
po prawej stronie operatora.
Wartość zwracana
true
jeśli po pair
lewej stronie operatora jest on ściśle mniejszy niż pair
po prawej stronie operatora; w przeciwnym razie false
.
Uwagi
Mówi left
pair
się, że obiekt jest ściśle mniejszy niż obiekt, right
pair
jeśli pozostawiony jest mniejszy niż i nie jest równy prawu.
W porównaniu par pierwsze elementy dwóch par mają najwyższy priorytet. Jeśli się różnią, wynik ich porównania jest traktowany jako wynik porównania pary. Jeśli wartości pierwszych elementów nie są różne, wartości drugiego elementu są porównywane, a wynik ich porównania jest brany pod uwagę w wyniku porównania pary.
Przykład
// utility_op_lt.cpp
// compile with: /EHsc
#include <utility>
#include <iomanip>
#include <iostream>
int main( )
{
using namespace std;
pair <int, double> p1, p2, p3;
p1 = make_pair ( 10, 2.22e-1 );
p2 = make_pair ( 100, 1.11e-1 );
p3 = make_pair ( 10, 1.11e-1 );
cout.precision ( 3 );
cout << "The pair p1 is: ( " << p1.first << ", "
<< p1.second << " )." << endl;
cout << "The pair p2 is: ( " << p2.first << ", "
<< p2.second << " )." << endl;
cout << "The pair p3 is: ( " << p3.first << ", "
<< p3.second << " )." << endl << endl;
if ( p1 < p2 )
cout << "The pair p1 is less than the pair p2." << endl;
else
cout << "The pair p1 is not less than the pair p2." << endl;
if ( p1 < p3 )
cout << "The pair p1 is less than the pair p3." << endl;
else
cout << "The pair p1 is not less than the pair p3." << endl;
}
The pair p1 is: ( 10, 0.222 ).
The pair p2 is: ( 100, 0.111 ).
The pair p3 is: ( 10, 0.111 ).
The pair p1 is less than the pair p2.
The pair p1 is not less than the pair p3.
operator<=
Sprawdza, czy obiekt pary po lewej stronie operatora jest mniejszy lub równy obiektowi pary po prawej stronie.
template <class Type>
constexpr bool operator<=(const Type& left, const Type& right);
template <class T, class U>
constexpr bool operator<=(const pair<T, U>& left, const pair<T, U>& right);
Parametry
Lewej
Obiekt typu pair
po lewej stronie operatora.
Prawo
Obiekt typu pair
po prawej stronie operatora.
Wartość zwracana
true
jeśli po pair
lewej stronie operatora jest mniejszy lub równy pair
prawej stronie operatora; w przeciwnym razie false
.
Uwagi
W porównaniu par pierwsze elementy dwóch par mają najwyższy priorytet. Jeśli się różnią, wynik ich porównania jest traktowany jako wynik porównania pary. Jeśli wartości pierwszych elementów nie są różne, wartości drugiego elementu są porównywane, a wynik ich porównania jest brany pod uwagę w wyniku porównania pary.
Przykład
// utility_op_le.cpp
// compile with: /EHsc
#include <utility>
#include <iomanip>
#include <iostream>
int main( )
{
using namespace std;
pair <int, double> p1, p2, p3, p4;
p1 = make_pair ( 10, 2.22e-1 );
p2 = make_pair ( 100, 1.11e-1 );
p3 = make_pair ( 10, 1.11e-1 );
p4 = make_pair ( 10, 2.22e-1 );
cout.precision ( 3 );
cout << "The pair p1 is: ( " << p1.first << ", "
<< p1.second << " )." << endl;
cout << "The pair p2 is: ( " << p2.first << ", "
<< p2.second << " )." << endl;
cout << "The pair p3 is: ( " << p3.first << ", "
<< p3.second << " )." << endl;
cout << "The pair p4 is: ( " << p4.first << ", "
<< p4.second << " )." << endl << endl;
if ( p1 <= p2 )
cout << "The pair p1 is less than or equal to the pair p2." << endl;
else
cout << "The pair p1 is greater than the pair p2." << endl;
if ( p1 <= p3 )
cout << "The pair p1 is less than or equal to the pair p3." << endl;
else
cout << "The pair p1 is greater than the pair p3." << endl;
if ( p1 <= p4 )
cout << "The pair p1 is less than or equal to the pair p4." << endl;
else
cout << "The pair p1 is greater than the pair p4." << endl;
}
The pair p1 is: ( 10, 0.222 ).
The pair p2 is: ( 100, 0.111 ).
The pair p3 is: ( 10, 0.111 ).
The pair p4 is: ( 10, 0.222 ).
The pair p1 is less than or equal to the pair p2.
The pair p1 is greater than the pair p3.
The pair p1 is less than or equal to the pair p4.
operator>
Sprawdza, czy obiekt pary po lewej stronie operatora jest większy niż obiekt pary po prawej stronie.
template <class Type>
constexpr bool operator>(const Type& left, const Type& right);
template <class T, class U>
constexpr bool operator>(const pair<T, U>& left, const pair<T, U>& right);
Parametry
Lewej
Obiekt typu pair
po lewej stronie operatora.
Prawo
Obiekt typu pair
po prawej stronie operatora.
Wartość zwracana
true
jeśli po pair
lewej stronie operatora jest ściśle większy niż pair
po prawej stronie operatora; w przeciwnym razie false
.
Uwagi
Mówi left
pair
się, że obiekt jest ściśle większy niż obiekt, right
pair
jeśli pozostawiony jest większy niż i nie równy prawu.
W porównaniu par pierwsze elementy dwóch par mają najwyższy priorytet. Jeśli się różnią, wynik ich porównania jest traktowany jako wynik porównania pary. Jeśli wartości pierwszych elementów nie są różne, wartości drugiego elementu są porównywane, a wynik ich porównania jest brany pod uwagę w wyniku porównania pary.
Przykład
// utility_op_gt.cpp
// compile with: /EHsc
#include <utility>
#include <iomanip>
#include <iostream>
int main( )
{
using namespace std;
pair <int, double> p1, p2, p3, p4;
p1 = make_pair ( 10, 2.22e-1 );
p2 = make_pair ( 100, 1.11e-1 );
p3 = make_pair ( 10, 1.11e-1 );
p4 = make_pair ( 10, 2.22e-1 );
cout.precision ( 3 );
cout << "The pair p1 is: ( " << p1.first << ", "
<< p1.second << " )." << endl;
cout << "The pair p2 is: ( " << p2.first << ", "
<< p2.second << " )." << endl;
cout << "The pair p3 is: ( " << p3.first << ", "
<< p3.second << " )." << endl;
cout << "The pair p4 is: ( " << p4.first << ", "
<< p4.second << " )." << endl << endl;
if ( p1 > p2 )
cout << "The pair p1 is greater than the pair p2." << endl;
else
cout << "The pair p1 is not greater than the pair p2." << endl;
if ( p1 > p3 )
cout << "The pair p1 is greater than the pair p3." << endl;
else
cout << "The pair p1 is not greater than the pair p3." << endl;
if ( p1 > p4 )
cout << "The pair p1 is greater than the pair p4." << endl;
else
cout << "The pair p1 is not greater than the pair p4." << endl;
}
The pair p1 is: ( 10, 0.222 ).
The pair p2 is: ( 100, 0.111 ).
The pair p3 is: ( 10, 0.111 ).
The pair p4 is: ( 10, 0.222 ).
The pair p1 is not greater than the pair p2.
The pair p1 is greater than the pair p3.
The pair p1 is not greater than the pair p4.
operator>=
Sprawdza, czy obiekt pary po lewej stronie operatora jest większy lub równy obiektowi pary po prawej stronie.
template <class Type>
constexpr bool operator>=(const Type& left, const Type& right);
template <class T, class U>
constexpr bool operator>=(const pair<T, U>& left, const pair<T, U>& right);
Parametry
Lewej
Obiekt typu pair
po lewej stronie operatora.
Prawo
Obiekt typu pair
po prawej stronie operatora.
Wartość zwracana
true
jeśli po pair
lewej stronie operatora jest większy lub równy pair
prawej stronie operatora; w przeciwnym razie false
.
Uwagi
W porównaniu par pierwsze elementy dwóch par mają najwyższy priorytet. Jeśli się różnią, wynik ich porównania jest traktowany jako wynik porównania pary. Jeśli wartości pierwszych elementów nie są różne, wartości drugiego elementu są porównywane, a wynik ich porównania jest brany pod uwagę w wyniku porównania pary.
Przykład
// utility_op_ge.cpp
// compile with: /EHsc
#include <utility>
#include <iomanip>
#include <iostream>
int main( )
{
using namespace std;
pair <int, double> p1, p2, p3, p4;
p1 = make_pair ( 10, 2.22e-1 );
p2 = make_pair ( 100, 1.11e-1 );
p3 = make_pair ( 10, 1.11e-1 );
p4 = make_pair ( 10, 2.22e-1 );
cout.precision ( 3 );
cout << "The pair p1 is: ( " << p1.first << ", "
<< p1.second << " )." << endl;
cout << "The pair p2 is: ( " << p2.first << ", "
<< p2.second << " )." << endl;
cout << "The pair p3 is: ( " << p3.first << ", "
<< p3.second << " )." << endl;
cout << "The pair p4 is: ( " << p4.first << ", "
<< p4.second << " )." << endl << endl;
if ( p1 >= p2 )
cout << "Pair p1 is greater than or equal to pair p2." << endl;
else
cout << "The pair p1 is less than the pair p2." << endl;
if ( p1 >= p3 )
cout << "Pair p1 is greater than or equal to pair p3." << endl;
else
cout << "The pair p1 is less than the pair p3." << endl;
if ( p1 >= p4 )
cout << "Pair p1 is greater than or equal to pair p4." << endl;
else
cout << "The pair p1 is less than the pair p4." << endl;
}
The pair p1 is: ( 10, 0.222 ).
The pair p2 is: ( 100, 0.111 ).
The pair p3 is: ( 10, 0.111 ).
The pair p4 is: ( 10, 0.222 ).
The pair p1 is less than the pair p2.
Pair p1 is greater than or equal to pair p3.
Pair p1 is greater than or equal to pair p4.
Opinia
https://aka.ms/ContentUserFeedback.
Dostępne już wkrótce: W 2024 r. będziemy stopniowo wycofywać zgłoszenia z serwisu GitHub jako mechanizm przesyłania opinii na temat zawartości i zastępować go nowym systemem opinii. Aby uzyskać więcej informacji, sprawdź:Prześlij i wyświetl opinię dla