1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // XFAIL: libcpp-no-exceptions 11 // <string> 12 13 // size_type capacity() const; 14 15 #include <string> 16 #include <cassert> 17 18 #include "test_allocator.h" 19 #include "min_allocator.h" 20 21 template <class S> 22 void 23 test(S s) 24 { 25 S::allocator_type::throw_after = 0; 26 try 27 { 28 while (s.size() < s.capacity()) 29 s.push_back(typename S::value_type()); 30 assert(s.size() == s.capacity()); 31 } 32 catch (...) 33 { 34 assert(false); 35 } 36 S::allocator_type::throw_after = INT_MAX; 37 } 38 39 int main() 40 { 41 { 42 typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S; 43 S s; 44 test(s); 45 s.assign(10, 'a'); 46 s.erase(5); 47 test(s); 48 s.assign(100, 'a'); 49 s.erase(50); 50 test(s); 51 } 52 #if TEST_STD_VER >= 11 53 { 54 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 55 S s; 56 assert(s.capacity() > 0); 57 } 58 #endif 59 } 60