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