1 // { dg-options "-std=gnu++17" }
3 // Copyright (C) 2013-2023 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // basic_string non-member functions
24 template<class charT, class traits, class Allocator>
25 bool operator==(const basic_string<charT,traits,Allocator>& lhs,
26 const basic_string<charT,traits,Allocator>& rhs);
28 template<class charT, class traits, class Allocator>
29 bool operator==(const charT* lhs,
30 const basic_string<charT,traits,Allocator>& rhs);
32 template<class charT, class traits, class Allocator>
33 bool operator==(const basic_string<charT,traits,Allocator>& lhs,
39 template<class charT, class traits, class Allocator>
40 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
41 const basic_string<charT,traits,Allocator>& rhs);
43 template<class charT, class traits, class Allocator>
44 bool operator!=(const charT* lhs,
45 const basic_string<charT,traits,Allocator>& rhs);
47 template<class charT, class traits, class Allocator>
48 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
54 template<class charT, class traits, class Allocator>
55 bool operator< (const basic_string<charT,traits,Allocator>& lhs,
56 const basic_string<charT,traits,Allocator>& rhs);
58 template<class charT, class traits, class Allocator>
59 bool operator< (const basic_string<charT,traits,Allocator>& lhs,
62 template<class charT, class traits, class Allocator>
63 bool operator< (const charT* lhs,
64 const basic_string<charT,traits,Allocator>& rhs);
69 template<class charT, class traits, class Allocator>
70 bool operator> (const basic_string<charT,traits,Allocator>& lhs,
71 const basic_string<charT,traits,Allocator>& rhs);
73 template<class charT, class traits, class Allocator>
74 bool operator> (const basic_string<charT,traits,Allocator>& lhs,
77 template<class charT, class traits, class Allocator>
78 bool operator> (const charT* lhs,
79 const basic_string<charT,traits,Allocator>& rhs);
84 template<class charT, class traits, class Allocator>
85 bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
86 const basic_string<charT,traits,Allocator>& rhs);
88 template<class charT, class traits, class Allocator>
89 bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
92 template<class charT, class traits, class Allocator>
93 bool operator<=(const charT* lhs,
94 const basic_string<charT,traits,Allocator>& rhs);
99 template<class charT, class traits, class Allocator>
100 bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
101 const basic_string<charT,traits,Allocator>& rhs);
103 template<class charT, class traits, class Allocator>
104 bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
107 template<class charT, class traits, class Allocator>
108 bool operator>=(const charT* lhs,
109 const basic_string<charT,traits,Allocator>& rhs);
112 namespace operators_2
{
117 gdb::string_view
str_0("costa rica");
118 gdb::string_view
str_1("costa marbella");
119 gdb::string_view
str_2("cost");
120 gdb::string_view
str_3("costa ricans");
121 gdb::string_view str_4
;
124 //comparisons between string objects
125 VERIFY( !(str_0
== str_1
) );
126 VERIFY( !(str_0
== str_2
) );
127 VERIFY( !(str_0
== str_3
) );
128 VERIFY( !(str_1
== str_0
) );
129 VERIFY( !(str_2
== str_0
) );
130 VERIFY( !(str_3
== str_0
) );
131 VERIFY( str_4
== str_0
);
132 VERIFY( str_0
== str_4
);
134 VERIFY( str_0
!= str_1
);
135 VERIFY( str_0
!= str_2
);
136 VERIFY( str_0
!= str_3
);
137 VERIFY( str_1
!= str_0
);
138 VERIFY( str_2
!= str_0
);
139 VERIFY( str_3
!= str_0
);
140 VERIFY( !(str_0
!= str_4
) );
141 VERIFY( !(str_4
!= str_0
) );
143 VERIFY( str_0
> str_1
); //true cuz r>m
144 VERIFY( str_0
> str_2
);
145 VERIFY( !(str_0
> str_3
) );
146 VERIFY( !(str_1
> str_0
) ); //false cuz m<r
147 VERIFY( !(str_2
> str_0
) );
148 VERIFY( str_3
> str_0
);
149 VERIFY( !(str_0
> str_4
) );
150 VERIFY( !(str_4
> str_0
) );
152 VERIFY( !(str_0
< str_1
) ); //false cuz r>m
153 VERIFY( !(str_0
< str_2
) );
154 VERIFY( str_0
< str_3
);
155 VERIFY( str_1
< str_0
); //true cuz m<r
156 VERIFY( str_2
< str_0
);
157 VERIFY( !(str_3
< str_0
) );
158 VERIFY( !(str_0
< str_4
) );
159 VERIFY( !(str_4
< str_0
) );
161 VERIFY( str_0
>= str_1
); //true cuz r>m
162 VERIFY( str_0
>= str_2
);
163 VERIFY( !(str_0
>= str_3
) );
164 VERIFY( !(str_1
>= str_0
) );//false cuz m<r
165 VERIFY( !(str_2
>= str_0
) );
166 VERIFY( str_3
>= str_0
);
167 VERIFY( str_0
>= str_4
);
168 VERIFY( str_4
>= str_0
);
170 VERIFY( !(str_0
<= str_1
) );//false cuz r>m
171 VERIFY( !(str_0
<= str_2
) );
172 VERIFY( str_0
<= str_3
);
173 VERIFY( str_1
<= str_0
);//true cuz m<r
174 VERIFY( str_2
<= str_0
);
175 VERIFY( !(str_3
<= str_0
) );
176 VERIFY( str_0
<= str_4
);
177 VERIFY( str_4
<= str_0
);
179 //comparisons between string object and string literal
180 VERIFY( !(str_0
== "costa marbella") );
181 VERIFY( !(str_0
== "cost") );
182 VERIFY( !(str_0
== "costa ricans") );
183 VERIFY( !("costa marbella" == str_0
) );
184 VERIFY( !("cost" == str_0
) );
185 VERIFY( !("costa ricans" == str_0
) );
186 VERIFY( "costa rica" == str_0
);
187 VERIFY( str_0
== "costa rica" );
189 VERIFY( str_0
!= "costa marbella" );
190 VERIFY( str_0
!= "cost" );
191 VERIFY( str_0
!= "costa ricans" );
192 VERIFY( "costa marbella" != str_0
);
193 VERIFY( "cost" != str_0
);
194 VERIFY( "costa ricans" != str_0
);
195 VERIFY( !("costa rica" != str_0
) );
196 VERIFY( !(str_0
!= "costa rica") );
198 VERIFY( str_0
> "costa marbella" ); //true cuz r>m
199 VERIFY( str_0
> "cost" );
200 VERIFY( !(str_0
> "costa ricans") );
201 VERIFY( !("costa marbella" > str_0
) );//false cuz m<r
202 VERIFY( !("cost" > str_0
) );
203 VERIFY( "costa ricans" > str_0
);
204 VERIFY( !("costa rica" > str_0
) );
205 VERIFY( !(str_0
> "costa rica") );
207 VERIFY( !(str_0
< "costa marbella") );//false cuz r>m
208 VERIFY( !(str_0
< "cost") );
209 VERIFY( str_0
< "costa ricans" );
210 VERIFY( "costa marbella" < str_0
);//true cuz m<r
211 VERIFY( "cost" < str_0
);
212 VERIFY( !("costa ricans" < str_0
) );
213 VERIFY( !("costa rica" < str_0
) );
214 VERIFY( !(str_0
< "costa rica") );
216 VERIFY( str_0
>= "costa marbella" );//true cuz r>m
217 VERIFY( str_0
>= "cost" );
218 VERIFY( !(str_0
>= "costa ricans") );
219 VERIFY( !("costa marbella" >= str_0
) );//false cuz m<r
220 VERIFY( !("cost" >= str_0
) );
221 VERIFY( "costa ricans" >= str_0
);
222 VERIFY( "costa rica" >= str_0
);
223 VERIFY( str_0
>= "costa rica" );
225 VERIFY( !(str_0
<= "costa marbella") );//false cuz r>m
226 VERIFY( !(str_0
<= "cost") );
227 VERIFY( str_0
<= "costa ricans" );
228 VERIFY( "costa marbella" <= str_0
);//true cuz m<r
229 VERIFY( "cost" <= str_0
);
230 VERIFY( !("costa ricans" <= str_0
) );
231 VERIFY( "costa rica" <= str_0
);
232 VERIFY( str_0
<= "costa rica" );
235 #ifndef GDB_STRING_VIEW
239 std::string_view
str_0("costa rica");
240 std::string_view
str_1("costa marbella");
241 std::string_view
str_2("cost");
242 std::string_view
str_3("costa ricans");
243 std::string_view str_4
;
246 #define VERIFY(x) if (!(x)) return false
249 //comparisons between string objects
250 VERIFY( !(str_0
== str_1
) );
251 VERIFY( !(str_0
== str_2
) );
252 VERIFY( !(str_0
== str_3
) );
253 VERIFY( !(str_1
== str_0
) );
254 VERIFY( !(str_2
== str_0
) );
255 VERIFY( !(str_3
== str_0
) );
256 VERIFY( str_4
== str_0
);
257 VERIFY( str_0
== str_4
);
259 VERIFY( str_0
!= str_1
);
260 VERIFY( str_0
!= str_2
);
261 VERIFY( str_0
!= str_3
);
262 VERIFY( str_1
!= str_0
);
263 VERIFY( str_2
!= str_0
);
264 VERIFY( str_3
!= str_0
);
265 VERIFY( !(str_0
!= str_4
) );
266 VERIFY( !(str_4
!= str_0
) );
268 VERIFY( str_0
> str_1
); //true cuz r>m
269 VERIFY( str_0
> str_2
);
270 VERIFY( !(str_0
> str_3
) );
271 VERIFY( !(str_1
> str_0
) ); //false cuz m<r
272 VERIFY( !(str_2
> str_0
) );
273 VERIFY( str_3
> str_0
);
274 VERIFY( !(str_0
> str_4
) );
275 VERIFY( !(str_4
> str_0
) );
277 VERIFY( !(str_0
< str_1
) ); //false cuz r>m
278 VERIFY( !(str_0
< str_2
) );
279 VERIFY( str_0
< str_3
);
280 VERIFY( str_1
< str_0
); //true cuz m<r
281 VERIFY( str_2
< str_0
);
282 VERIFY( !(str_3
< str_0
) );
283 VERIFY( !(str_0
< str_4
) );
284 VERIFY( !(str_4
< str_0
) );
286 VERIFY( str_0
>= str_1
); //true cuz r>m
287 VERIFY( str_0
>= str_2
);
288 VERIFY( !(str_0
>= str_3
) );
289 VERIFY( !(str_1
>= str_0
) );//false cuz m<r
290 VERIFY( !(str_2
>= str_0
) );
291 VERIFY( str_3
>= str_0
);
292 VERIFY( str_0
>= str_4
);
293 VERIFY( str_4
>= str_0
);
295 VERIFY( !(str_0
<= str_1
) );//false cuz r>m
296 VERIFY( !(str_0
<= str_2
) );
297 VERIFY( str_0
<= str_3
);
298 VERIFY( str_1
<= str_0
);//true cuz m<r
299 VERIFY( str_2
<= str_0
);
300 VERIFY( !(str_3
<= str_0
) );
301 VERIFY( str_0
<= str_4
);
302 VERIFY( str_4
<= str_0
);
304 //comparisons between string object and string literal
305 VERIFY( !(str_0
== "costa marbella") );
306 VERIFY( !(str_0
== "cost") );
307 VERIFY( !(str_0
== "costa ricans") );
308 VERIFY( !("costa marbella" == str_0
) );
309 VERIFY( !("cost" == str_0
) );
310 VERIFY( !("costa ricans" == str_0
) );
311 VERIFY( "costa rica" == str_0
);
312 VERIFY( str_0
== "costa rica" );
314 VERIFY( str_0
!= "costa marbella" );
315 VERIFY( str_0
!= "cost" );
316 VERIFY( str_0
!= "costa ricans" );
317 VERIFY( "costa marbella" != str_0
);
318 VERIFY( "cost" != str_0
);
319 VERIFY( "costa ricans" != str_0
);
320 VERIFY( !("costa rica" != str_0
) );
321 VERIFY( !(str_0
!= "costa rica") );
323 VERIFY( str_0
> "costa marbella" ); //true cuz r>m
324 VERIFY( str_0
> "cost" );
325 VERIFY( !(str_0
> "costa ricans") );
326 VERIFY( !("costa marbella" > str_0
) );//false cuz m<r
327 VERIFY( !("cost" > str_0
) );
328 VERIFY( "costa ricans" > str_0
);
329 VERIFY( !("costa rica" > str_0
) );
330 VERIFY( !(str_0
> "costa rica") );
332 VERIFY( !(str_0
< "costa marbella") );//false cuz r>m
333 VERIFY( !(str_0
< "cost") );
334 VERIFY( str_0
< "costa ricans" );
335 VERIFY( "costa marbella" < str_0
);//true cuz m<r
336 VERIFY( "cost" < str_0
);
337 VERIFY( !("costa ricans" < str_0
) );
338 VERIFY( !("costa rica" < str_0
) );
339 VERIFY( !(str_0
< "costa rica") );
341 VERIFY( str_0
>= "costa marbella" );//true cuz r>m
342 VERIFY( str_0
>= "cost" );
343 VERIFY( !(str_0
>= "costa ricans") );
344 VERIFY( !("costa marbella" >= str_0
) );//false cuz m<r
345 VERIFY( !("cost" >= str_0
) );
346 VERIFY( "costa ricans" >= str_0
);
347 VERIFY( "costa rica" >= str_0
);
348 VERIFY( str_0
>= "costa rica" );
350 VERIFY( !(str_0
<= "costa marbella") );//false cuz r>m
351 VERIFY( !(str_0
<= "cost") );
352 VERIFY( str_0
<= "costa ricans" );
353 VERIFY( "costa marbella" <= str_0
);//true cuz m<r
354 VERIFY( "cost" <= str_0
);
355 VERIFY( !("costa ricans" <= str_0
) );
356 VERIFY( "costa rica" <= str_0
);
357 VERIFY( str_0
<= "costa rica" );
367 #ifndef GDB_STRING_VIEW
368 static_assert( test02() );
373 } // namespace operators_2