[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.capacity / shrink_to_fit.pass.cpp
blob2c6ce0df6f9fb3e7c3e37a1427111a13a52c8c7b
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // <string>
11 // void shrink_to_fit();
13 #include <string>
14 #include <cassert>
16 #include "test_macros.h"
17 #include "min_allocator.h"
19 template <class S>
20 void
21 test(S s)
23 typename S::size_type old_cap = s.capacity();
24 S s0 = s;
25 s.shrink_to_fit();
26 LIBCPP_ASSERT(s.__invariants());
27 assert(s == s0);
28 assert(s.capacity() <= old_cap);
29 assert(s.capacity() >= s.size());
32 int main(int, char**)
35 typedef std::string S;
36 S s;
37 test(s);
39 s.assign(10, 'a');
40 s.erase(5);
41 test(s);
43 s.assign(100, 'a');
44 s.erase(50);
45 test(s);
47 #if TEST_STD_VER >= 11
49 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
50 S s;
51 test(s);
53 s.assign(10, 'a');
54 s.erase(5);
55 test(s);
57 s.assign(100, 'a');
58 s.erase(50);
59 test(s);
61 #endif
63 return 0;