]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/1.cc
3 // Copyright (C) 1999-2021 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.3 string capacity
23 #include <testsuite_hooks.h>
27 // POD types : resize, capacity, reserve
29 typedef std::string::size_type size_type_s
;
31 size_type_s sz01
= str01
.capacity();
33 size_type_s sz02
= str01
.capacity();
34 VERIFY( sz02
>= sz01
);
35 VERIFY( sz02
>= 100 );
36 #if __cplusplus <= 201703L
39 str01
.shrink_to_fit(); // reserve is deprecated in C++20
41 sz01
= str01
.capacity();
42 VERIFY( sz01
< sz02
);
44 // P0966: reserve should not shrink
46 sz01
= str01
.capacity();
47 str01
.reserve(sz01
- 1);
48 VERIFY( str01
.capacity() == sz01
);
50 sz01
= str01
.size() + 5;
53 VERIFY( sz01
== sz02
);
55 sz01
= str01
.size() - 5;
58 VERIFY( sz01
== sz02
);
60 std::string
str05(30, 'q');
61 std::string str06
= str05
;
62 str05
= str06
+ str05
;
63 VERIFY( str05
.capacity() >= str05
.size() );
64 VERIFY( str06
.capacity() >= str06
.size() );
66 // POD types: size, length, max_size, clear(), empty()
70 VERIFY( b01
== true );
72 sz02
= str01
.length();
73 VERIFY( sz01
== sz02
);
76 sz02
= str01
.length();
77 VERIFY( sz01
== sz02
);
79 sz01
= str01
.length();
81 str011
= str01
+ "_addendum_";
83 sz02
= str01
.length();
84 VERIFY( sz01
== sz02
);
85 sz02
= str011
.length();
86 VERIFY( sz02
> sz01
);
88 // trickster allocator issues involved with these:
89 std::string str3
= "8-chars_8-chars_";
90 std::string str4
= str3
+ "7-chars";
93 sz02
= str01
.max_size();
94 VERIFY( sz02
>= sz01
);
99 VERIFY( b01
== true );
101 VERIFY( sz01
>= sz02
);