Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / utilities / meta / meta.unary / meta.unary.prop / is_swappable.pass.cpp
blob925ddad28136b82fe7ad29d34bdbcd7e47a60e97
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: c++03, c++11, c++14
11 // type_traits
13 // is_swappable
15 #include <type_traits>
16 #include <utility>
17 #include <vector>
18 #include "test_macros.h"
20 namespace MyNS {
22 // Make the test types non-copyable so that generic std::swap is not valid.
23 struct A {
24 A(A const&) = delete;
25 A& operator=(A const&) = delete;
28 struct B {
29 B(B const&) = delete;
30 B& operator=(B const&) = delete;
33 struct C {};
34 struct D {};
36 void swap(A&, A&) {}
38 void swap(A&, B&) {}
39 void swap(B&, A&) {}
41 void swap(A&, C&) {} // missing swap(C, A)
42 void swap(D&, C&) {}
44 struct M {
45 M(M const&) = delete;
46 M& operator=(M const&) = delete;
49 void swap(M&&, M&&) {}
51 struct DeletedSwap {
52 friend void swap(DeletedSwap&, DeletedSwap&) = delete;
55 } // namespace MyNS
57 namespace MyNS2 {
59 struct AmbiguousSwap {};
61 template <class T>
62 void swap(T&, T&) {}
64 } // end namespace MyNS2
66 int main(int, char**)
68 using namespace MyNS;
70 // Test that is_swappable applies an lvalue reference to the type.
71 static_assert(std::is_swappable<A>::value, "");
72 static_assert(std::is_swappable<A&>::value, "");
73 static_assert(!std::is_swappable<M>::value, "");
74 static_assert(!std::is_swappable<M&&>::value, "");
76 static_assert(!std::is_swappable<B>::value, "");
77 static_assert(std::is_swappable<C>::value, "");
79 // test non-referencable types
80 static_assert(!std::is_swappable<void>::value, "");
81 static_assert(!std::is_swappable<int() const>::value, "");
82 static_assert(!std::is_swappable<int() &>::value, "");
85 // test that a deleted swap is correctly handled.
86 static_assert(!std::is_swappable<DeletedSwap>::value, "");
89 // test that a swap with ambiguous overloads is handled correctly.
90 static_assert(!std::is_swappable<MyNS2::AmbiguousSwap>::value, "");
93 // test for presence of is_swappable_v
94 static_assert(std::is_swappable_v<int>, "");
95 static_assert(!std::is_swappable_v<M>, "");
98 return 0;