Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / strings / string.view / string.view.modifiers / swap.pass.cpp
blobde0c5f423c4e8ee8cf23e6fc4667ac399ba6e1d2
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 // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14)
11 // <string_view>
13 // void swap(basic_string_view& _other) noexcept
15 #include <string_view>
16 #include <cassert>
18 #include "test_macros.h"
20 template <typename CharT>
21 void test(const CharT* s, std::size_t len) {
22 typedef std::basic_string_view<CharT> SV;
24 SV sv1(s);
25 SV sv2;
27 assert(sv1.size() == len);
28 assert(sv1.data() == s);
29 assert(sv2.size() == 0);
31 sv1.swap(sv2);
32 assert(sv1.size() == 0);
33 assert(sv2.size() == len);
34 assert(sv2.data() == s);
38 #if TEST_STD_VER > 11
39 constexpr std::size_t test_ce(size_t n, size_t k) {
40 typedef std::basic_string_view<char> SV;
41 SV sv1{"ABCDEFGHIJKL", n};
42 SV sv2{sv1.data(), k};
43 sv1.swap(sv2);
44 return sv1.size();
46 #endif
48 int main(int, char**) {
49 test("ABCDE", 5);
50 test("a", 1);
51 test("", 0);
53 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
54 test(L"ABCDE", 5);
55 test(L"a", 1);
56 test(L"", 0);
57 #endif
59 #if TEST_STD_VER >= 11
60 test(u"ABCDE", 5);
61 test(u"a", 1);
62 test(u"", 0);
64 test(U"ABCDE", 5);
65 test(U"a", 1);
66 test(U"", 0);
67 #endif
69 #if TEST_STD_VER > 11
71 static_assert(test_ce(2, 3) == 3, "");
72 static_assert(test_ce(5, 3) == 3, "");
73 static_assert(test_ce(0, 1) == 1, "");
75 #endif
77 return 0;