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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
15 #include <type_traits>
18 #include "test_macros.h"
22 // Make the test types non-copyable so that generic std::swap is not valid.
25 A
& operator=(A
const&) = delete;
30 B
& operator=(B
const&) = delete;
41 void swap(A
&, C
&) {} // missing swap(C, A)
46 M
& operator=(M
const&) = delete;
49 void swap(M
&&, M
&&) {}
52 friend void swap(DeletedSwap
&, DeletedSwap
&) = delete;
59 struct AmbiguousSwap
{};
64 } // end namespace MyNS2
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
>, "");