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 // void shrink_to_fit();
13 
14 #include <string>
15 #include <cassert>
16 
17 #include "min_allocator.h"
18 
19 template <class S>
20 void
test(S s)21 test(S s)
22 {
23     typename S::size_type old_cap = s.capacity();
24     S s0 = s;
25     s.shrink_to_fit();
26     assert(s.__invariants());
27     assert(s == s0);
28     assert(s.capacity() <= old_cap);
29     assert(s.capacity() >= s.size());
30 }
31 
main()32 int main()
33 {
34     {
35     typedef std::string S;
36     S s;
37     test(s);
38 
39     s.assign(10, 'a');
40     s.erase(5);
41     test(s);
42 
43     s.assign(100, 'a');
44     s.erase(50);
45     test(s);
46     }
47 #if __cplusplus >= 201103L
48     {
49     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
50     S s;
51     test(s);
52 
53     s.assign(10, 'a');
54     s.erase(5);
55     test(s);
56 
57     s.assign(100, 'a');
58     s.erase(50);
59     test(s);
60     }
61 #endif
62 }
63