1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // template<ValueType T, size_t N>
12 // requires Swappable<T>
14 // swap(T (&a)[N], T (&b)[N]);
19 #include <type_traits>
22 #include "test_macros.h"
25 #if TEST_STD_VER >= 11
28 CopyOnly(CopyOnly
const&) noexcept
{}
29 CopyOnly
& operator=(CopyOnly
const&) { return *this; }
33 struct NoexceptMoveOnly
{
35 NoexceptMoveOnly(NoexceptMoveOnly
&&) noexcept
{}
36 NoexceptMoveOnly
& operator=(NoexceptMoveOnly
&&) noexcept
{ return *this; }
39 struct NotMoveConstructible
{
40 NotMoveConstructible() {}
41 NotMoveConstructible
& operator=(NotMoveConstructible
&&) { return *this; }
43 NotMoveConstructible(NotMoveConstructible
&&);
47 auto can_swap_test(int) -> decltype(std::swap(std::declval
<Tp
>(), std::declval
<Tp
>()));
50 auto can_swap_test(...) -> std::false_type
;
53 constexpr bool can_swap() {
54 return std::is_same
<decltype(can_swap_test
<Tp
>(0)), void>::value
;
59 constexpr bool test_swap_constexpr()
71 #endif // TEST_STD_VER > 17
86 #if TEST_STD_VER >= 11
88 std::unique_ptr
<int> i
[3];
89 for (int k
= 0; k
< 3; ++k
)
90 i
[k
].reset(new int(k
+1));
91 std::unique_ptr
<int> j
[3];
92 for (int k
= 0; k
< 3; ++k
)
93 j
[k
].reset(new int(k
+4));
103 using CA
= CopyOnly
[42];
104 using MA
= NoexceptMoveOnly
[42];
105 using NA
= NotMoveConstructible
[42];
106 static_assert(can_swap
<CA
&>(), "");
107 static_assert(can_swap
<MA
&>(), "");
108 static_assert(!can_swap
<NA
&>(), "");
112 static_assert(!noexcept(std::swap(ca
, ca
)), "");
113 static_assert(noexcept(std::swap(ma
, ma
)), "");
117 #if TEST_STD_VER > 17
118 static_assert(test_swap_constexpr());
119 #endif // TEST_STD_VER > 17