1 // 1998-10-01, 1999-06-25 bkoz
3 // Copyright (C) 1998-1999 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 2, 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 COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 21.3.7.1 basic_string non-member functions
23 // 21.3.7.2 operator==
25 template<class charT, class traits, class Allocator>
26 bool operator==(const basic_string<charT,traits,Allocator>& lhs,
27 const basic_string<charT,traits,Allocator>& rhs);
29 template<class charT, class traits, class Allocator>
30 bool operator==(const charT* lhs,
31 const basic_string<charT,traits,Allocator>& rhs);
33 template<class charT, class traits, class Allocator>
34 bool operator==(const basic_string<charT,traits,Allocator>& lhs,
38 // 21.3.7.3 operator!=
40 template<class charT, class traits, class Allocator>
41 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
42 const basic_string<charT,traits,Allocator>& rhs);
44 template<class charT, class traits, class Allocator>
45 bool operator!=(const charT* lhs,
46 const basic_string<charT,traits,Allocator>& rhs);
48 template<class charT, class traits, class Allocator>
49 bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
55 template<class charT, class traits, class Allocator>
56 bool operator< (const basic_string<charT,traits,Allocator>& lhs,
57 const basic_string<charT,traits,Allocator>& rhs);
59 template<class charT, class traits, class Allocator>
60 bool operator< (const basic_string<charT,traits,Allocator>& lhs,
63 template<class charT, class traits, class Allocator>
64 bool operator< (const charT* lhs,
65 const basic_string<charT,traits,Allocator>& rhs);
70 template<class charT, class traits, class Allocator>
71 bool operator> (const basic_string<charT,traits,Allocator>& lhs,
72 const basic_string<charT,traits,Allocator>& rhs);
74 template<class charT, class traits, class Allocator>
75 bool operator> (const basic_string<charT,traits,Allocator>& lhs,
78 template<class charT, class traits, class Allocator>
79 bool operator> (const charT* lhs,
80 const basic_string<charT,traits,Allocator>& rhs);
85 template<class charT, class traits, class Allocator>
86 bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
87 const basic_string<charT,traits,Allocator>& rhs);
89 template<class charT, class traits, class Allocator>
90 bool operator<=(const basic_string<charT,traits,Allocator>& lhs,
93 template<class charT, class traits, class Allocator>
94 bool operator<=(const charT* lhs,
95 const basic_string<charT,traits,Allocator>& rhs);
98 // 21.3.7.7 operator>=
100 template<class charT, class traits, class Allocator>
101 bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
102 const basic_string<charT,traits,Allocator>& rhs);
104 template<class charT, class traits, class Allocator>
105 bool operator>=(const basic_string<charT,traits,Allocator>& lhs,
108 template<class charT, class traits, class Allocator>
109 bool operator>=(const charT* lhs,
110 const basic_string<charT,traits,Allocator>& rhs);
114 #include <debug_assert.h>
119 std::string
str_0("costa rica");
120 std::string
str_1("costa marbella");
121 std::string
str_2("cost");
122 std::string
str_3("costa ricans");
126 //comparisons between string objects
127 VERIFY( !(str_0
== str_1
) );
128 VERIFY( !(str_0
== str_2
) );
129 VERIFY( !(str_0
== str_3
) );
130 VERIFY( !(str_1
== str_0
) );
131 VERIFY( !(str_2
== str_0
) );
132 VERIFY( !(str_3
== str_0
) );
133 VERIFY( str_4
== str_0
);
134 VERIFY( str_0
== str_4
);
136 VERIFY( str_0
!= str_1
);
137 VERIFY( str_0
!= str_2
);
138 VERIFY( str_0
!= str_3
);
139 VERIFY( str_1
!= str_0
);
140 VERIFY( str_2
!= str_0
);
141 VERIFY( str_3
!= str_0
);
142 VERIFY( !(str_0
!= str_4
) );
143 VERIFY( !(str_4
!= str_0
) );
145 VERIFY( str_0
> str_1
); //true cuz r>m
146 VERIFY( str_0
> str_2
);
147 VERIFY( !(str_0
> str_3
) );
148 VERIFY( !(str_1
> str_0
) ); //false cuz m<r
149 VERIFY( !(str_2
> str_0
) );
150 VERIFY( str_3
> str_0
);
151 VERIFY( !(str_0
> str_4
) );
152 VERIFY( !(str_4
> str_0
) );
154 VERIFY( !(str_0
< str_1
) ); //false cuz r>m
155 VERIFY( !(str_0
< str_2
) );
156 VERIFY( str_0
< str_3
);
157 VERIFY( str_1
< str_0
); //true cuz m<r
158 VERIFY( str_2
< str_0
);
159 VERIFY( !(str_3
< str_0
) );
160 VERIFY( !(str_0
< str_4
) );
161 VERIFY( !(str_4
< str_0
) );
163 VERIFY( str_0
>= str_1
); //true cuz r>m
164 VERIFY( str_0
>= str_2
);
165 VERIFY( !(str_0
>= str_3
) );
166 VERIFY( !(str_1
>= str_0
) );//false cuz m<r
167 VERIFY( !(str_2
>= str_0
) );
168 VERIFY( str_3
>= str_0
);
169 VERIFY( str_0
>= str_4
);
170 VERIFY( str_4
>= str_0
);
172 VERIFY( !(str_0
<= str_1
) );//false cuz r>m
173 VERIFY( !(str_0
<= str_2
) );
174 VERIFY( str_0
<= str_3
);
175 VERIFY( str_1
<= str_0
);//true cuz m<r
176 VERIFY( str_2
<= str_0
);
177 VERIFY( !(str_3
<= str_0
) );
178 VERIFY( str_0
<= str_4
);
179 VERIFY( str_4
<= str_0
);
181 //comparisons between string object and string literal
182 VERIFY( !(str_0
== "costa marbella") );
183 VERIFY( !(str_0
== "cost") );
184 VERIFY( !(str_0
== "costa ricans") );
185 VERIFY( !("costa marbella" == str_0
) );
186 VERIFY( !("cost" == str_0
) );
187 VERIFY( !("costa ricans" == str_0
) );
188 VERIFY( "costa rica" == str_0
);
189 VERIFY( str_0
== "costa rica" );
191 VERIFY( str_0
!= "costa marbella" );
192 VERIFY( str_0
!= "cost" );
193 VERIFY( str_0
!= "costa ricans" );
194 VERIFY( "costa marbella" != str_0
);
195 VERIFY( "cost" != str_0
);
196 VERIFY( "costa ricans" != str_0
);
197 VERIFY( !("costa rica" != str_0
) );
198 VERIFY( !(str_0
!= "costa rica") );
200 VERIFY( str_0
> "costa marbella" ); //true cuz r>m
201 VERIFY( str_0
> "cost" );
202 VERIFY( !(str_0
> "costa ricans") );
203 VERIFY( !("costa marbella" > str_0
) );//false cuz m<r
204 VERIFY( !("cost" > str_0
) );
205 VERIFY( "costa ricans" > str_0
);
206 VERIFY( !("costa rica" > str_0
) );
207 VERIFY( !(str_0
> "costa rica") );
209 VERIFY( !(str_0
< "costa marbella") );//false cuz r>m
210 VERIFY( !(str_0
< "cost") );
211 VERIFY( str_0
< "costa ricans" );
212 VERIFY( "costa marbella" < str_0
);//true cuz m<r
213 VERIFY( "cost" < str_0
);
214 VERIFY( !("costa ricans" < str_0
) );
215 VERIFY( !("costa rica" < str_0
) );
216 VERIFY( !(str_0
< "costa rica") );
218 VERIFY( str_0
>= "costa marbella" );//true cuz r>m
219 VERIFY( str_0
>= "cost" );
220 VERIFY( !(str_0
>= "costa ricans") );
221 VERIFY( !("costa marbella" >= str_0
) );//false cuz m<r
222 VERIFY( !("cost" >= str_0
) );
223 VERIFY( "costa ricans" >= str_0
);
224 VERIFY( "costa rica" >= str_0
);
225 VERIFY( str_0
>= "costa rica" );
227 VERIFY( !(str_0
<= "costa marbella") );//false cuz r>m
228 VERIFY( !(str_0
<= "cost") );
229 VERIFY( str_0
<= "costa ricans" );
230 VERIFY( "costa marbella" <= str_0
);//true cuz m<r
231 VERIFY( "cost" <= str_0
);
232 VERIFY( !("costa ricans" <= str_0
) );
233 VERIFY( "costa rica" <= str_0
);
234 VERIFY( str_0
<= "costa rica" );
236 // 21.3.7.1 operator+
238 template<class charT, class traits, class Allocator>
239 basic_string<charT,traits,Allocator>
240 operator+(const basic_string<charT,traits,Allocator>& lhs,
241 const basic_string<charT,traits,Allocator>& rhs);
243 template<class charT, class traits, class Allocator>
244 basic_string<charT,traits,Allocator>
245 operator+(const charT* lhs,
246 const basic_string<charT,traits,Allocator>& rhs);
248 template<class charT, class traits, class Allocator>
249 basic_string<charT,traits,Allocator>
250 operator+(const basic_string<charT,traits,Allocator>& lhs,
253 template<class charT, class traits, class Allocator>
254 basic_string<charT,traits,Allocator>
255 operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
257 template<class charT, class traits, class Allocator>
258 basic_string<charT,traits,Allocator>
259 operator+(const basic_string<charT,traits,Allocator>& lhs, charT rhs);
262 str_4
= str_0
+ "ns";
263 VERIFY( str_4
== str_3
);
265 const std::string
str_5(" marbella");
266 str_4
= "costa" + str_5
;
267 VERIFY( str_4
== str_1
);
269 std::string
str_6("ns");
270 str_4
= str_0
+ str_6
;
271 VERIFY( str_4
== str_3
);
275 VERIFY( str_4
== str_3
);
287 VERIFY( str_4
== str_3
);