• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 //===----------------------------------------------------------------------===//
8 
9 // <string>
10 
11 // size_type capacity() const;
12 
13 #include <string>
14 #include <cassert>
15 
16 #include "test_allocator.h"
17 #include "min_allocator.h"
18 
19 #include "test_macros.h"
20 
21 template <class S>
22 void
test(S s)23 test(S s)
24 {
25     S::allocator_type::throw_after = 0;
26 #ifndef TEST_HAS_NO_EXCEPTIONS
27     try
28 #endif
29     {
30         while (s.size() < s.capacity())
31             s.push_back(typename S::value_type());
32         assert(s.size() == s.capacity());
33     }
34 #ifndef TEST_HAS_NO_EXCEPTIONS
35     catch (...)
36     {
37         assert(false);
38     }
39 #endif
40     S::allocator_type::throw_after = INT_MAX;
41 }
42 
main(int,char **)43 int main(int, char**)
44 {
45     {
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);
55     }
56 #if TEST_STD_VER >= 11
57     {
58     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
59     S s;
60     assert(s.capacity() > 0);
61     }
62 #endif
63 
64   return 0;
65 }
66