Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / basic.string / string.nonmembers / string.special / swap.pass.cpp
blobda6fc11c14329f47ebdd18469965a97781776863
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 //===----------------------------------------------------------------------===//
9 // <string>
11 // template<class charT, class traits, class Allocator>
12 // void swap(basic_string<charT,traits,Allocator>& lhs,
13 // basic_string<charT,traits,Allocator>& rhs); // constexpr since C++20
15 #include <string>
16 #include <stdexcept>
17 #include <algorithm>
18 #include <cassert>
20 #include "test_macros.h"
21 #include "min_allocator.h"
23 template <class S>
24 TEST_CONSTEXPR_CXX20 void test(S s1, S s2) {
25 S s1_ = s1;
26 S s2_ = s2;
27 swap(s1, s2);
28 LIBCPP_ASSERT(s1.__invariants());
29 LIBCPP_ASSERT(s2.__invariants());
30 assert(s1 == s2_);
31 assert(s2 == s1_);
34 template <class S>
35 TEST_CONSTEXPR_CXX20 void test_string() {
36 test(S(""), S(""));
37 test(S(""), S("12345"));
38 test(S(""), S("1234567890"));
39 test(S(""), S("12345678901234567890"));
40 test(S("abcde"), S(""));
41 test(S("abcde"), S("12345"));
42 test(S("abcde"), S("1234567890"));
43 test(S("abcde"), S("12345678901234567890"));
44 test(S("abcdefghij"), S(""));
45 test(S("abcdefghij"), S("12345"));
46 test(S("abcdefghij"), S("1234567890"));
47 test(S("abcdefghij"), S("12345678901234567890"));
48 test(S("abcdefghijklmnopqrst"), S(""));
49 test(S("abcdefghijklmnopqrst"), S("12345"));
50 test(S("abcdefghijklmnopqrst"), S("1234567890"));
51 test(S("abcdefghijklmnopqrst"), S("12345678901234567890"));
54 TEST_CONSTEXPR_CXX20 bool test() {
55 test_string<std::string>();
56 #if TEST_STD_VER >= 11
57 test_string<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
58 #endif
60 return true;
63 int main(int, char**) {
64 test();
65 #if TEST_STD_VER > 17
66 static_assert(test());
67 #endif
69 return 0;