Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // <string> |
| 11 | |
| 12 | // size_type capacity() const; |
| 13 | |
| 14 | #include <string> |
| 15 | #include <cassert> |
| 16 | |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 17 | #include "test_allocator.h" |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 18 | #include "min_allocator.h" |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | |
| 20 | template <class S> |
| 21 | void |
| 22 | test(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 | |
| 38 | int main() |
| 39 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 40 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 41 | 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 Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 50 | } |
| 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 58 | } |