blob: 20f8cb54b470c36a6942d3f35e989f8bb8bfa711 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
12// size_type capacity() const;
13
14#include <string>
15#include <cassert>
16
17#include "../test_allocator.h"
18
19template <class S>
20void
21test(S s)
22{
23 S::allocator_type::throw_after = 0;
24 try
25 {
26 while (s.size() < s.capacity())
27 s.push_back(typename S::value_type());
28 assert(s.size() == s.capacity());
29 }
30 catch (...)
31 {
32 assert(false);
33 }
34 S::allocator_type::throw_after = INT_MAX;
35}
36
37int main()
38{
39 typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S;
40 S s;
41 test(s);
42 s.assign(10, 'a');
43 s.erase(5);
44 test(s);
45 s.assign(100, 'a');
46 s.erase(50);
47 test(s);
48}