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