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 template <class S>
20 void
test(S s1,S s2)21 test(S s1, S s2)
22 {
23 S s1_ = s1;
24 S s2_ = s2;
25 s1.swap(s2);
26 assert(s1.__invariants());
27 assert(s2.__invariants());
28 assert(s1 == s2_);
29 assert(s2 == s1_);
30 }
31
main()32 int main()
33 {
34 typedef std::string S;
35 test(S(""), S(""));
36 test(S(""), S("12345"));
37 test(S(""), S("1234567890"));
38 test(S(""), S("12345678901234567890"));
39 test(S("abcde"), S(""));
40 test(S("abcde"), S("12345"));
41 test(S("abcde"), S("1234567890"));
42 test(S("abcde"), S("12345678901234567890"));
43 test(S("abcdefghij"), S(""));
44 test(S("abcdefghij"), S("12345"));
45 test(S("abcdefghij"), S("1234567890"));
46 test(S("abcdefghij"), S("12345678901234567890"));
47 test(S("abcdefghijklmnopqrst"), S(""));
48 test(S("abcdefghijklmnopqrst"), S("12345"));
49 test(S("abcdefghijklmnopqrst"), S("1234567890"));
50 test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
51 }
52