]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/operators/char/cmp_c++20.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 21_strings / basic_string / operators / char / cmp_c++20.cc
1 // Copyright (C) 2020-2021 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
20
21 // C++20 21.3.3.2 Non-member comparison functions [string.cmp]
22
23 // operator==
24 /*
25 template<class charT, class traits, class Allocator>
26 constexpr bool
27 operator==(const basic_string<charT, traits, Allocator>& lhs,
28 const basic_string<charT, traits, Allocator>& rhs);
29
30 template<class charT, class traits, class Allocator>
31 constexpr bool
32 operator==(const basic_string<charT, traits, Allocator>& lhs,
33 const charT* rhs);
34 */
35
36 // operator<=>
37 /*
38 template<class charT, class traits, class Allocator>
39 constexpr [see below]
40 operator<=>(const basic_string<charT, traits, Allocator>& lhs,
41 const basic_string<charT, traits, Allocator>& rhs);
42
43 template<class charT, class traits, class Allocator>
44 constexpr [see below]
45 operator<=>(const basic_string<charT,traits,Allocator>& lhs,
46 const charT* rhs);
47 */
48
49 #include <string>
50 #include <testsuite_hooks.h>
51
52 void
53 test01()
54 {
55 std::string str_0("costa rica");
56 std::string str_1("costa marbella");
57 std::string str_2("cost");
58 std::string str_3("costa ricans");
59 std::string str_4;
60
61 str_4 = str_0;
62 //comparisons between string objects
63 VERIFY( !(str_0 == str_1) );
64 VERIFY( !(str_0 == str_2) );
65 VERIFY( !(str_0 == str_3) );
66 VERIFY( !(str_1 == str_0) );
67 VERIFY( !(str_2 == str_0) );
68 VERIFY( !(str_3 == str_0) );
69 VERIFY( str_4 == str_0 );
70 VERIFY( str_0 == str_4 );
71
72 VERIFY( str_0 != str_1 );
73 VERIFY( str_0 != str_2 );
74 VERIFY( str_0 != str_3 );
75 VERIFY( str_1 != str_0 );
76 VERIFY( str_2 != str_0 );
77 VERIFY( str_3 != str_0 );
78 VERIFY( !(str_0 != str_4) );
79 VERIFY( !(str_4 != str_0) );
80
81 VERIFY( str_0 > str_1 ); //true cuz r>m
82 VERIFY( str_0 > str_2 );
83 VERIFY( !(str_0 > str_3) );
84 VERIFY( !(str_1 > str_0) ); //false cuz m<r
85 VERIFY( !(str_2 > str_0) );
86 VERIFY( str_3 > str_0 );
87 VERIFY( !(str_0 > str_4) );
88 VERIFY( !(str_4 > str_0) );
89
90 VERIFY( !(str_0 < str_1) ); //false cuz r>m
91 VERIFY( !(str_0 < str_2) );
92 VERIFY( str_0 < str_3 );
93 VERIFY( str_1 < str_0 ); //true cuz m<r
94 VERIFY( str_2 < str_0 );
95 VERIFY( !(str_3 < str_0) );
96 VERIFY( !(str_0 < str_4) );
97 VERIFY( !(str_4 < str_0) );
98
99 VERIFY( str_0 >= str_1 ); //true cuz r>m
100 VERIFY( str_0 >= str_2 );
101 VERIFY( !(str_0 >= str_3) );
102 VERIFY( !(str_1 >= str_0) );//false cuz m<r
103 VERIFY( !(str_2 >= str_0) );
104 VERIFY( str_3 >= str_0 );
105 VERIFY( str_0 >= str_4 );
106 VERIFY( str_4 >= str_0 );
107
108 VERIFY( !(str_0 <= str_1) );//false cuz r>m
109 VERIFY( !(str_0 <= str_2) );
110 VERIFY( str_0 <= str_3 );
111 VERIFY( str_1 <= str_0 );//true cuz m<r
112 VERIFY( str_2 <= str_0 );
113 VERIFY( !(str_3 <= str_0) );
114 VERIFY( str_0 <= str_4 );
115 VERIFY( str_4 <= str_0 );
116
117 VERIFY( std::is_gt(str_0 <=> str_1) );
118 VERIFY( std::is_gt(str_0 <=> str_2) );
119 VERIFY( std::is_lt(str_0 <=> str_3) );
120 VERIFY( std::is_eq(str_0 <=> str_4) );
121 VERIFY( std::is_lt(str_1 <=> str_0) );
122 VERIFY( std::is_lt(str_2 <=> str_0) );
123 VERIFY( std::is_gt(str_3 <=> str_0) );
124 VERIFY( std::is_eq(str_4 <=> str_0) );
125
126 //comparisons between string object and string literal
127 VERIFY( !(str_0 == "costa marbella") );
128 VERIFY( !(str_0 == "cost") );
129 VERIFY( !(str_0 == "costa ricans") );
130 VERIFY( !("costa marbella" == str_0) );
131 VERIFY( !("cost" == str_0) );
132 VERIFY( !("costa ricans" == str_0) );
133 VERIFY( "costa rica" == str_0 );
134 VERIFY( str_0 == "costa rica" );
135
136 VERIFY( str_0 != "costa marbella" );
137 VERIFY( str_0 != "cost" );
138 VERIFY( str_0 != "costa ricans" );
139 VERIFY( "costa marbella" != str_0 );
140 VERIFY( "cost" != str_0 );
141 VERIFY( "costa ricans" != str_0 );
142 VERIFY( !("costa rica" != str_0) );
143 VERIFY( !(str_0 != "costa rica") );
144
145 VERIFY( str_0 > "costa marbella" ); //true cuz r>m
146 VERIFY( str_0 > "cost" );
147 VERIFY( !(str_0 > "costa ricans") );
148 VERIFY( !("costa marbella" > str_0) );//false cuz m<r
149 VERIFY( !("cost" > str_0) );
150 VERIFY( "costa ricans" > str_0 );
151 VERIFY( !("costa rica" > str_0) );
152 VERIFY( !(str_0 > "costa rica") );
153
154 VERIFY( !(str_0 < "costa marbella") );//false cuz r>m
155 VERIFY( !(str_0 < "cost") );
156 VERIFY( str_0 < "costa ricans" );
157 VERIFY( "costa marbella" < str_0 );//true cuz m<r
158 VERIFY( "cost" < str_0 );
159 VERIFY( !("costa ricans" < str_0) );
160 VERIFY( !("costa rica" < str_0) );
161 VERIFY( !(str_0 < "costa rica") );
162
163 VERIFY( str_0 >= "costa marbella" );//true cuz r>m
164 VERIFY( str_0 >= "cost" );
165 VERIFY( !(str_0 >= "costa ricans") );
166 VERIFY( !("costa marbella" >= str_0) );//false cuz m<r
167 VERIFY( !("cost" >= str_0) );
168 VERIFY( "costa ricans" >= str_0 );
169 VERIFY( "costa rica" >= str_0 );
170 VERIFY( str_0 >= "costa rica" );
171
172 VERIFY( !(str_0 <= "costa marbella") );//false cuz r>m
173 VERIFY( !(str_0 <= "cost") );
174 VERIFY( str_0 <= "costa ricans" );
175 VERIFY( "costa marbella" <= str_0 );//true cuz m<r
176 VERIFY( "cost" <= str_0 );
177 VERIFY( !("costa ricans" <= str_0) );
178 VERIFY( "costa rica" <= str_0 );
179 VERIFY( str_0 <= "costa rica" );
180
181 VERIFY( std::is_gt(str_0 <=> "costa marbella") );
182 VERIFY( std::is_gt(str_0 <=> "cost") );
183 VERIFY( std::is_lt(str_0 <=> "costa ricans") );
184 VERIFY( std::is_eq(str_0 <=> "costa rica") );
185 VERIFY( std::is_lt("costa marbella" <=> str_0) );
186 VERIFY( std::is_lt("cost" <=> str_0) );
187 VERIFY( std::is_gt("costa ricans" <=> str_0) );
188 VERIFY( std::is_eq("costa rica" <=> str_0) );
189 }
190
191 int main()
192 {
193 test01();
194 }