blob: bae762155527fd7e3edb4698adf7b36ddb3f4541 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
12// size_type capacity() const;
13
14#include <string>
15#include <cassert>
16
Marshall Clow1b921882013-12-03 00:18:10 +000017#include "test_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000018#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019
20template <class S>
21void
22test(S s)
23{
24 S::allocator_type::throw_after = 0;
25 try
26 {
27 while (s.size() < s.capacity())
28 s.push_back(typename S::value_type());
29 assert(s.size() == s.capacity());
30 }
31 catch (...)
32 {
33 assert(false);
34 }
35 S::allocator_type::throw_after = INT_MAX;
36}
37
38int main()
39{
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000040 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000041 typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S;
42 S s;
43 test(s);
44 s.assign(10, 'a');
45 s.erase(5);
46 test(s);
47 s.assign(100, 'a');
48 s.erase(50);
49 test(s);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000050 }
51#if __cplusplus >= 201103L
52 {
53 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
54 S s;
55 assert(s.capacity() > 0);
56 }
57#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000058}