[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.capacity / reserve.pass.cpp
bloba200a6357257e5c39c9123fb7fdeaac36eba6247
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 reserve(); // Deprecated in C++20.
13 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
15 #include <string>
16 #include <stdexcept>
17 #include <cassert>
19 #include "test_macros.h"
20 #include "min_allocator.h"
22 template <class S>
23 void
24 test(typename S::size_type min_cap, typename S::size_type erased_index)
26 S s(min_cap, 'a');
27 s.erase(erased_index);
28 assert(s.size() == erased_index);
29 assert(s.capacity() >= min_cap); // Check that we really have at least this capacity.
31 typename S::size_type old_cap = s.capacity();
32 S s0 = s;
33 s.reserve();
34 LIBCPP_ASSERT(s.__invariants());
35 assert(s == s0);
36 assert(s.capacity() <= old_cap);
37 assert(s.capacity() >= s.size());
40 int main(int, char**)
43 typedef std::string S;
45 test<S>(0, 0);
46 test<S>(10, 5);
47 test<S>(100, 50);
50 #if TEST_STD_VER >= 11
52 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
54 test<S>(0, 0);
55 test<S>(10, 5);
56 test<S>(100, 50);
59 #endif
61 return 0;