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