3 // Copyright (C) 1999-2019 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 // 21.3 template class basic_string
24 #include <testsuite_hooks.h>
26 // Do a quick sanity check on known problems with element access and
27 // ref-counted strings. These should all pass, regardless of the
28 // underlying string implementation, of course.
31 typedef std::string::size_type csize_type
;
32 typedef std::string::iterator siterator
;
33 typedef std::string::reverse_iterator sriterator
;
34 csize_type csz01
, csz02
;
38 std::string
str01("montara beach, half moon bay");
39 const std::string
str02("ocean beach, san francisco");
44 // References, pointers, and iterators referring to the elements of
45 // a basic_string may be invalidated by the following uses of that
46 // basic_string object:
50 // Susequent to any of the above uses except the forms of insert()
51 // and erase() which return iterators, the first call to non-const
52 // member functions operator[](), at(), begin(), rbegin(), end(), or
58 VERIFY( str01
[0] == 'x' );
59 VERIFY( str03
[0] == 'm' );
63 rit1
= str01
.rbegin(); // NB: Pointing at one-past the end, so ...
64 *rit1
= 'z'; // ... but it's taken care of here
65 VERIFY( str01
[csz01
- 1] == 'z' );
66 VERIFY( str03
[csz01
- 1] == 'y' );
70 std::string::reference r1
= str01
.at(csz01
- 2);
71 VERIFY( str03
== str01
);
73 VERIFY( str01
[csz01
- 2] == 'd' );
74 VERIFY( str03
[csz01
- 2] == 'a' );
78 std::string::reference r2
= str01
[csz01
- 3];
79 VERIFY( str03
== str01
);
81 VERIFY( str01
[csz01
- 3] == 'w' );
82 VERIFY( str03
[csz01
- 3] == 'b' );
87 VERIFY( str03
== str01
);
90 VERIFY( str01
[csz02
- 1] == 'q' );
91 VERIFY( str03
[csz02
- 1] == 'z' );
95 VERIFY( str03
== str01
);
98 VERIFY( str01
[0] == 'p' );
99 VERIFY( str03
[0] == 'x' );
101 // need to also test for const begin/const end