[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.capacity / capacity.pass.cpp
blob02187c5193af9aa2204e7a460d8892a7c2461ee1
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 // size_type capacity() const;
13 #include <string>
14 #include <cassert>
16 #include "test_allocator.h"
17 #include "min_allocator.h"
19 #include "test_macros.h"
21 template <class S>
22 void
23 test(S s)
25 S::allocator_type::throw_after = 0;
26 #ifndef TEST_HAS_NO_EXCEPTIONS
27 try
28 #endif
30 while (s.size() < s.capacity())
31 s.push_back(typename S::value_type());
32 assert(s.size() == s.capacity());
34 #ifndef TEST_HAS_NO_EXCEPTIONS
35 catch (...)
37 assert(false);
39 #endif
40 S::allocator_type::throw_after = INT_MAX;
43 int main(int, char**)
46 typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S;
47 S s;
48 test(s);
49 s.assign(10, 'a');
50 s.erase(5);
51 test(s);
52 s.assign(100, 'a');
53 s.erase(50);
54 test(s);
56 #if TEST_STD_VER >= 11
58 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
59 S s;
60 assert(s.capacity() > 0);
62 #endif
64 return 0;