[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/utility/pair/operator_cmp [Back]  [Original]

operator==,!=,<,<=,>,>=,<=>(std::pair) cppreference.com
cppreference.com

operator==,!=,<,<=,>,>=,<=>(std::pair)

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
 
 
<tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody>
(1)
template< class T1, class T2, class U1, class U2 > bool operator==( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
template< class T1, class T2, class U1, class U2 > constexpr bool operator==( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
(2)
template< class T1, class T2, class U1, class U2 > bool operator!=( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
template< class T1, class T2, class U1, class U2 > constexpr bool operator!=( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
( C++20)
(3)
template< class T1, class T2, class U1, class U2 > bool operator<( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
template< class T1, class T2, class U1, class U2 > constexpr bool operator<( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
( C++20)
(4)
template< class T1, class T2, class U1, class U2 > bool operator<=( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
template< class T1, class T2, class U1, class U2 > constexpr bool operator<=( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
( C++20)
(5)
template< class T1, class T2, class U1, class U2 > bool operator>( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
template< class T1, class T2, class U1, class U2 > constexpr bool operator>( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
( C++20)
(6)
template< class T1, class T2, class U1, class U2 > bool operator>=( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
template< class T1, class T2, class U1, class U2 > constexpr bool operator>=( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
( C++14)
( C++20)
template< class T1, class T2, class U1, class U2 > constexpr std::common_comparison_category_t<synth-three-way-result<T1, U1>, synth-three-way-result<T2, U2>> operator<=>( const std::pair<T1, T2>& lhs, const std::pair<U1, U2>& rhs );
(7) ( C++20)
1,2) , lhs rhs, lhs.first rhs.first lhs.second rhs.second.
3-6) lhs rhs operator<, , , .
7) lhs rhs synth-three-way, , , . synth-three-way-result synth-three-way.

<, <=, >, >= != operator<=> operator== .

( C++20)

lhs, rhs

1) true, lhs.first == rhs.first, lhs.second == rhs.second, false
2) !(lhs == rhs)
3) lhs.first < rhs.first, true. , rhs.first < lhs.first, false. , lhs.second < rhs.second, true. false.
4) !(rhs < lhs)
5) rhs < lhs
6) !(lhs < rhs)
7) synth-three-way(lhs.first, rhs.first), 0, synth-three-way(lhs.second, rhs.second).

operator< , .

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

int main()
{
    std::vector<std::pair<int, std::string>> v = {{2, "baz"},
                                                  {2, "bar"},
                                                  {1, "foo"}};
    std::sort(v.begin(), v.end());
    
    for (auto p: v)
        std::cout << '{' << p.first << ", " << std::quoted(p.second) << "}\n";
}

:

{1, "foo"}
{2, "bar"}
{2, "baz"}

C++:

LWG 296 C++98 , == <,
LWG 3865 C++98 pair pair

( C++20)( C++20)( C++20)( C++20)( C++20)(C++20)

( ) []

Web Proxy Viewer  |  New URL  |  Original Page