blob: 5bc1c8a9153fd3a06c63a1b31aac827e203efdc8 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
Howard Hinnant6e0a1f42010-08-22 00:47:54 +000012// basic_string<charT,traits,Allocator>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000013// operator=(basic_string<charT,traits,Allocator>&& str);
14
15#include <string>
16#include <cassert>
17
Dan Albert1d4a1ed2016-05-25 22:36:09 -070018#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
19
Marshall Clow1b921882013-12-03 00:18:10 +000020#include "test_allocator.h"
Marshall Clow061d0cc2013-11-26 20:58:02 +000021#include "min_allocator.h"
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022
23template <class S>
24void
25test(S s1, S s2)
26{
27 S s0 = s2;
28 s1 = std::move(s2);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070029 assert(s1.__invariants());
30 assert(s2.__invariants());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000031 assert(s1 == s0);
32 assert(s1.capacity() >= s1.size());
33}
34
Dan Albert1d4a1ed2016-05-25 22:36:09 -070035#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
36
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000037int main()
38{
Dan Albert1d4a1ed2016-05-25 22:36:09 -070039#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000040 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000041 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"));
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000057 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070058#if __cplusplus >= 201103L
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000059 {
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 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -070077#endif
78#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000079}