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 // basic_string<charT,traits,Allocator>& 13 // operator=(basic_string<charT,traits,Allocator>&& str); 14 15 #include <string> 16 #include <cassert> 17 18 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 19 20 #include "test_allocator.h" 21 #include "min_allocator.h" 22 23 template <class S> 24 void 25 test(S s1, S s2) 26 { 27 S s0 = s2; 28 s1 = std::move(s2); 29 assert(s1.__invariants()); 30 assert(s2.__invariants()); 31 assert(s1 == s0); 32 assert(s1.capacity() >= s1.size()); 33 } 34 35 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 36 37 int main() 38 { 39 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 40 { 41 typedef std::string S; 42 test(S(), S()); 43 test(S("1"), S()); 44 test(S(), S("1")); 45 test(S("1"), S("2")); 46 test(S("1"), S("2")); 47 48 test(S(), 49 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 50 test(S("123456789"), 51 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 52 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 53 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 54 test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 55 "1234567890123456789012345678901234567890123456789012345678901234567890"), 56 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 57 } 58 #if __cplusplus >= 201103L 59 { 60 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 61 test(S(), S()); 62 test(S("1"), S()); 63 test(S(), S("1")); 64 test(S("1"), S("2")); 65 test(S("1"), S("2")); 66 67 test(S(), 68 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 69 test(S("123456789"), 70 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 71 test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 72 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 73 test(S("1234567890123456789012345678901234567890123456789012345678901234567890" 74 "1234567890123456789012345678901234567890123456789012345678901234567890"), 75 S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz")); 76 } 77 #endif 78 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 79 } 80