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 swap(basic_string& s); 13 14 #include <string> 15 #include <stdexcept> 16 #include <algorithm> 17 #include <cassert> 18 19 #include "test_macros.h" 20 #include "min_allocator.h" 21 22 template <class S> 23 void 24 test(S s1, S s2) 25 { 26 S s1_ = s1; 27 S s2_ = s2; 28 s1.swap(s2); 29 LIBCPP_ASSERT(s1.__invariants()); 30 LIBCPP_ASSERT(s2.__invariants()); 31 assert(s1 == s2_); 32 assert(s2 == s1_); 33 } 34 35 int main() 36 { 37 { 38 typedef std::string S; 39 test(S(""), S("")); 40 test(S(""), S("12345")); 41 test(S(""), S("1234567890")); 42 test(S(""), S("12345678901234567890")); 43 test(S("abcde"), S("")); 44 test(S("abcde"), S("12345")); 45 test(S("abcde"), S("1234567890")); 46 test(S("abcde"), S("12345678901234567890")); 47 test(S("abcdefghij"), S("")); 48 test(S("abcdefghij"), S("12345")); 49 test(S("abcdefghij"), S("1234567890")); 50 test(S("abcdefghij"), S("12345678901234567890")); 51 test(S("abcdefghijklmnopqrst"), S("")); 52 test(S("abcdefghijklmnopqrst"), S("12345")); 53 test(S("abcdefghijklmnopqrst"), S("1234567890")); 54 test(S("abcdefghijklmnopqrst"), S("12345678901234567890")); 55 } 56 #if TEST_STD_VER >= 11 57 { 58 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 59 test(S(""), S("")); 60 test(S(""), S("12345")); 61 test(S(""), S("1234567890")); 62 test(S(""), S("12345678901234567890")); 63 test(S("abcde"), S("")); 64 test(S("abcde"), S("12345")); 65 test(S("abcde"), S("1234567890")); 66 test(S("abcde"), S("12345678901234567890")); 67 test(S("abcdefghij"), S("")); 68 test(S("abcdefghij"), S("12345")); 69 test(S("abcdefghij"), S("1234567890")); 70 test(S("abcdefghij"), S("12345678901234567890")); 71 test(S("abcdefghijklmnopqrst"), S("")); 72 test(S("abcdefghijklmnopqrst"), S("12345")); 73 test(S("abcdefghijklmnopqrst"), S("1234567890")); 74 test(S("abcdefghijklmnopqrst"), S("12345678901234567890")); 75 } 76 #endif 77 } 78