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