Home | History | Annotate | Download | only in string.capacity
      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 // <string>
     11 
     12 // size_type capacity() const;
     13 
     14 #include <string>
     15 #include <cassert>
     16 
     17 #include "test_allocator.h"
     18 #include "min_allocator.h"
     19 
     20 #include "test_macros.h"
     21 
     22 template <class S>
     23 void
     24 test(S s)
     25 {
     26     S::allocator_type::throw_after = 0;
     27 #ifndef TEST_HAS_NO_EXCEPTIONS
     28     try
     29 #endif
     30     {
     31         while (s.size() < s.capacity())
     32             s.push_back(typename S::value_type());
     33         assert(s.size() == s.capacity());
     34     }
     35 #ifndef TEST_HAS_NO_EXCEPTIONS
     36     catch (...)
     37     {
     38         assert(false);
     39     }
     40 #endif
     41     S::allocator_type::throw_after = INT_MAX;
     42 }
     43 
     44 int main()
     45 {
     46     {
     47     typedef std::basic_string<char, std::char_traits<char>, test_allocator<char> > S;
     48     S s;
     49     test(s);
     50     s.assign(10, 'a');
     51     s.erase(5);
     52     test(s);
     53     s.assign(100, 'a');
     54     s.erase(50);
     55     test(s);
     56     }
     57 #if TEST_STD_VER >= 11
     58     {
     59     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
     60     S s;
     61     assert(s.capacity() > 0);
     62     }
     63 #endif
     64 }
     65