1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <string>
10 
11 // template<class charT, class traits, class Allocator>
12 //   void swap(basic_string<charT,traits,Allocator>& lhs,
13 //             basic_string<charT,traits,Allocator>& rhs);
14 
15 #include <string>
16 #include <stdexcept>
17 #include <algorithm>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "min_allocator.h"
22 
23 template <class S>
24 void
25 test(S s1, S s2)
26 {
27     S s1_ = s1;
28     S s2_ = s2;
29     swap(s1, s2);
30     LIBCPP_ASSERT(s1.__invariants());
31     LIBCPP_ASSERT(s2.__invariants());
32     assert(s1 == s2_);
33     assert(s2 == s1_);
34 }
35 
36 int main(int, char**)
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 TEST_STD_VER >= 11
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   return 0;
80 }
81