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 // XFAIL: LIBCXX-AIX-FIXME
10 
11 // <string>
12 
13 // template<class charT, class traits, class Allocator>
14 //   void swap(basic_string<charT,traits,Allocator>& lhs,
15 //             basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20
16 
17 #include <string>
18 #include <stdexcept>
19 #include <algorithm>
20 #include <cassert>
21 
22 #include "test_macros.h"
23 #include "min_allocator.h"
24 
25 template <class S>
26 TEST_CONSTEXPR_CXX20 void
27 test(S s1, S s2)
28 {
29     S s1_ = s1;
30     S s2_ = s2;
31     swap(s1, s2);
32     LIBCPP_ASSERT(s1.__invariants());
33     LIBCPP_ASSERT(s2.__invariants());
34     assert(s1 == s2_);
35     assert(s2 == s1_);
36 }
37 
38 TEST_CONSTEXPR_CXX20 bool test() {
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   return true;
81 }
82 
83 int main(int, char**)
84 {
85   test();
86 #if TEST_STD_VER > 17
87   static_assert(test());
88 #endif
89 
90   return 0;
91 }
92