1 // 24.1.5 Random access iterators
2 // 24.3.1 Iterator traits
3 // (basic_string and vector implementations)
5 // Copyright (C) 1999, 2003, 2004, 2005 Free Software Foundation, Inc.
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program 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
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
24 #include <testsuite_hooks.h>
31 std::string
s("abcde");
33 std::string::iterator
i1(s
.begin());
63 std::string::iterator i2
;
65 std::iterator_traits
<std::string::iterator
>::difference_type d1
;
70 std::iterator_traits
<std::string::iterator
>::value_type v1
;
75 std::iterator_traits
<std::string::iterator
>::reference
r1(i1
[0]);
83 if ((i1
!= i2
) != true)
85 if ((i1
== i2
) != false)
87 if ((i1
< i2
) != true)
89 if ((i1
> i2
) != false)
91 if ((i1
<= i2
) != true)
93 if ((i1
>= i2
) != false)
96 std::string::iterator i3
;
98 if ((i3
== i1
) != true)
102 if ((i3
== i2
) != true)
106 if ((i3
== i1
) != true)
131 std::string::const_iterator
ci1(s
.begin());
161 std::string::const_iterator ci2
;
163 std::iterator_traits
<std::string::const_iterator
>::difference_type d2
;
168 std::iterator_traits
<std::string::const_iterator
>::value_type v2
;
173 std::iterator_traits
<std::string::const_iterator
>::reference
r2(ci1
[0]);
177 if ((ci1
!= ci2
) != true)
179 if ((ci1
== ci2
) != false)
181 if ((ci1
< ci2
) != true)
183 if ((ci1
> ci2
) != false)
185 if ((ci1
<= ci2
) != true)
187 if ((ci1
>= ci2
) != false)
190 std::string::const_iterator ci3
;
192 if ((ci3
== ci1
) != true)
196 if ((ci3
== ci2
) != true)
200 if ((ci3
== ci1
) != true)
218 // iterator and const_iterator
219 std::string::const_iterator
ci4(i1
);
220 if ((ci4
== i1
) != true)
222 if ((ci4
!= i1
) != false)
224 if ((ci4
< i1
) != false)
226 if ((ci4
> i1
) != false)
228 if ((ci4
<= i1
) != true)
230 if ((ci4
>= i1
) != true)
233 if ((i2
== ci4
) != true)
235 if ((i2
< ci4
) != false)
237 if ((i2
> ci4
) != false)
239 if ((i2
<= ci4
) != true)
241 if ((i2
>= ci4
) != true)
244 const std::string
cs("ABCDE");
245 std::string::const_iterator
ci5(cs
.begin());
264 std::vector
<int>::iterator
i1(v
.begin());
294 std::vector
<int>::iterator i2
;
296 std::iterator_traits
<std::vector
<int>::iterator
>::difference_type d1
;
301 std::iterator_traits
<std::vector
<int>::iterator
>::value_type v1
;
306 std::iterator_traits
<std::vector
<int>::iterator
>::reference
r1(i1
[0]);
314 if ((i1
!= i2
) != true)
316 if ((i1
== i2
) != false)
318 if ((i1
< i2
) != true)
320 if ((i1
> i2
) != false)
322 if ((i1
<= i2
) != true)
324 if ((i1
>= i2
) != false)
327 std::vector
<int>::iterator i3
;
329 if ((i3
== i1
) != true)
333 if ((i3
== i2
) != true)
337 if ((i3
== i1
) != true)
362 std::vector
<int>::const_iterator
ci1(v
.begin());
392 std::vector
<int>::const_iterator ci2
;
394 std::iterator_traits
<std::vector
<int>::const_iterator
>::difference_type d2
;
399 std::iterator_traits
<std::vector
<int>::const_iterator
>::value_type v2
;
404 std::iterator_traits
<std::vector
<int>::const_iterator
>::reference
409 if ((ci1
!= ci2
) != true)
411 if ((ci1
== ci2
) != false)
413 if ((ci1
< ci2
) != true)
415 if ((ci1
> ci2
) != false)
417 if ((ci1
<= ci2
) != true)
419 if ((ci1
>= ci2
) != false)
422 std::vector
<int>::const_iterator ci3
;
424 if ((ci3
== ci1
) != true)
428 if ((ci3
== ci2
) != true)
432 if ((ci3
== ci1
) != true)
450 // iterator to const_iterator
451 std::vector
<int>::const_iterator
ci4(i1
);
452 if ((ci4
== i1
) != true)
454 if ((ci4
!= i1
) != false)
456 if ((ci4
< i1
) != false)
458 if ((ci4
> i1
) != false)
460 if ((ci4
<= i1
) != true)
462 if ((ci4
>= i1
) != true)
465 if ((i2
== ci4
) != true)
467 if ((i2
< ci4
) != false)
469 if ((i2
> ci4
) != false)
471 if ((i2
<= ci4
) != true)
473 if ((i2
>= ci4
) != true)
476 const std::vector
<int> cv(v
);
477 std::vector
<int>::const_iterator
ci5(cv
.begin());
481 std::vector
<std::string
> vs
;
482 vs
.push_back(std::string("abc"));
483 std::vector
<std::string
>::iterator
ivs(vs
.begin());
484 if (ivs
->c_str()[1] != 'b')
495 std::string
s("abcde");
497 std::string::reverse_iterator
ri(s
.rbegin());
501 std::iterator_traits
<std::string::reverse_iterator
>::difference_type d
;
506 const std::string
cs("abcde");
507 std::string::const_reverse_iterator
cri(cs
.rend());
508 if (cri
- 5 != cs
.rbegin())
514 // the following should be compiler errors
515 // flag runtime errors in case they slip through the compiler
522 extern void f(std::vector
<std::string
*>::iterator
);
523 std::vector
<std::string
*> vs
[2];
524 f(vs
); // address of array is not an iterator
530 char *i
= s
.begin(); // begin() doesn't return a pointer
535 std::string::const_iterator ci
;
536 std::string::iterator i
;
537 if (i
- ci
) // remove const_ is a warning
539 // failures++; only a warning
543 std::vector
<char>::iterator iv
;
544 std::string::iterator
is(iv
);// vector<char> is not string
549 std::vector
<char>::iterator iv
;
550 std::string::iterator is
;
551 if (iv
== is
) // vector<char> is not string
557 std::vector
<char>::const_iterator ci
;
558 std::vector
<char>::iterator i
= ci
; // remove const_ is a warning
560 // failures++; only a warning
564 std::vector
<int> v(1);
565 std::vector
<int>::const_iterator
ci(v
.begin());
566 *ci
= 1; // cannot assign through const_iterator
571 std::vector
<const int> v(1);
572 std::vector
<const int>::reference
r(v
.begin()[0]);
573 r
= 1; // cannot assign through reference to const
585 std::string::iterator it
= s
.begin();
586 std::string::const_iterator cit
= s
.begin();
596 failures
+= string_stuff();
598 failures
+= vector_stuff();
600 failures
+= reverse_stuff();
602 failures
+= wrong_stuff();
604 failures
+= test6642();
606 VERIFY(failures
== 0);