1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <utility>
10
11// template <class T1, class T2> struct pair
12
13// template <class T1, class T2, class U1, class U2> bool operator==(const pair<T1,T2>&, const pair<U1,U2>&);
14// template <class T1, class T2, class U1, class U2> bool operator!=(const pair<T1,T2>&, const pair<U1,U2>&);
15// template <class T1, class T2, class U1, class U2> bool operator< (const pair<T1,T2>&, const pair<U1,U2>&);
16// template <class T1, class T2, class U1, class U2> bool operator> (const pair<T1,T2>&, const pair<U1,U2>&);
17// template <class T1, class T2, class U1, class U2> bool operator>=(const pair<T1,T2>&, const pair<U1,U2>&);
18// template <class T1, class T2, class U1, class U2> bool operator<=(const pair<T1,T2>&, const pair<U1,U2>&);
19
20#include <utility>
21#include <cassert>
22#include <concepts>
23
24#include "test_macros.h"
25
26#if TEST_STD_VER >= 26
27
28// Test SFINAE.
29
30struct EqualityComparable {
31 constexpr EqualityComparable(int value) : value_{value} {};
32
33 friend constexpr bool operator==(const EqualityComparable&, const EqualityComparable&) noexcept = default;
34
35 int value_;
36};
37
38static_assert(std::equality_comparable<EqualityComparable>);
39
40static_assert(std::equality_comparable<std::pair<EqualityComparable, EqualityComparable>>);
41
42struct NonComparable {};
43
44static_assert(!std::equality_comparable<NonComparable>);
45
46static_assert(!std::equality_comparable<std::pair<EqualityComparable, NonComparable>>);
47static_assert(!std::equality_comparable<std::pair<NonComparable, EqualityComparable>>);
48
49#endif // TEST_STD_VER >= 26
50
51int main(int, char**)
52{
53 {
54 typedef std::pair<int, short> P1;
55 typedef std::pair<long, long> P2;
56 P1 p1(3, static_cast<short>(4));
57 P2 p2(3, 4);
58 assert( (p1 == p2));
59 assert(!(p1 != p2));
60 assert(!(p1 < p2));
61 assert( (p1 <= p2));
62 assert(!(p1 > p2));
63 assert( (p1 >= p2));
64 }
65 {
66 typedef std::pair<int, short> P;
67 P p1(3, static_cast<short>(4));
68 P p2(3, static_cast<short>(4));
69 assert( (p1 == p2));
70 assert(!(p1 != p2));
71 assert(!(p1 < p2));
72 assert( (p1 <= p2));
73 assert(!(p1 > p2));
74 assert( (p1 >= p2));
75 }
76 {
77 typedef std::pair<int, short> P;
78 P p1(2, static_cast<short>(4));
79 P p2(3, static_cast<short>(4));
80 assert(!(p1 == p2));
81 assert( (p1 != p2));
82 assert( (p1 < p2));
83 assert( (p1 <= p2));
84 assert(!(p1 > p2));
85 assert(!(p1 >= p2));
86 }
87 {
88 typedef std::pair<int, short> P;
89 P p1(3, static_cast<short>(2));
90 P p2(3, static_cast<short>(4));
91 assert(!(p1 == p2));
92 assert( (p1 != p2));
93 assert( (p1 < p2));
94 assert( (p1 <= p2));
95 assert(!(p1 > p2));
96 assert(!(p1 >= p2));
97 }
98 {
99 typedef std::pair<int, short> P;
100 P p1(3, static_cast<short>(4));
101 P p2(2, static_cast<short>(4));
102 assert(!(p1 == p2));
103 assert( (p1 != p2));
104 assert(!(p1 < p2));
105 assert(!(p1 <= p2));
106 assert( (p1 > p2));
107 assert( (p1 >= p2));
108 }
109 {
110 typedef std::pair<int, short> P;
111 P p1(3, static_cast<short>(4));
112 P p2(3, static_cast<short>(2));
113 assert(!(p1 == p2));
114 assert( (p1 != p2));
115 assert(!(p1 < p2));
116 assert(!(p1 <= p2));
117 assert( (p1 > p2));
118 assert( (p1 >= p2));
119 }
120
121#if TEST_STD_VER > 11
122 {
123 typedef std::pair<int, short> P;
124 constexpr P p1(3, static_cast<short>(4));
125 constexpr P p2(3, static_cast<short>(2));
126 static_assert(!(p1 == p2), "");
127 static_assert( (p1 != p2), "");
128 static_assert(!(p1 < p2), "");
129 static_assert(!(p1 <= p2), "");
130 static_assert( (p1 > p2), "");
131 static_assert( (p1 >= p2), "");
132 }
133#endif
134
135 return 0;
136}
137

source code of libcxx/test/std/utilities/utility/pairs/pairs.spec/comparison.pass.cpp