Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame^] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure |
| 4 | // |
| 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 | |
| 19 | template <class S> |
| 20 | void |
| 21 | test(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 | |
| 37 | int 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 | } |