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>
17 #include "test_macros.h"
21 // Make the test types non-copyable so that generic std::swap is not valid.
24 A
& operator=(A
const&) = delete;
29 B
& operator=(B
const&) = delete;
32 void swap(A
&, A
&) noexcept
{}
37 M
& operator=(M
const&) = delete;
40 void swap(M
&&, M
&&) noexcept
{}
43 ThrowingMove(ThrowingMove
&&) {}
44 ThrowingMove
& operator=(ThrowingMove
&&) { return *this; }
53 // Test that is_swappable applies an lvalue reference to the type.
54 static_assert(std::is_nothrow_swappable
<int>::value
, "");
55 static_assert(std::is_nothrow_swappable
<int&>::value
, "");
56 static_assert(!std::is_nothrow_swappable
<M
>::value
, "");
57 static_assert(!std::is_nothrow_swappable
<M
&&>::value
, "");
60 // Test that it correctly deduces the noexcept of swap.
61 static_assert(std::is_nothrow_swappable
<A
>::value
, "");
62 static_assert(!std::is_nothrow_swappable
<B
>::value
63 && std::is_swappable
<B
>::value
, "");
64 static_assert(!std::is_nothrow_swappable
<ThrowingMove
>::value
65 && std::is_swappable
<ThrowingMove
>::value
, "");
68 // Test that it doesn't drop the qualifiers
69 static_assert(!std::is_nothrow_swappable
<const A
>::value
, "");
72 // test non-referenceable types
73 static_assert(!std::is_nothrow_swappable
<void>::value
, "");
74 static_assert(!std::is_nothrow_swappable
<int() const>::value
, "");
75 static_assert(!std::is_nothrow_swappable
<int(int, ...) const &>::value
, "");
78 // test for presence of is_nothrow_swappable_v
79 static_assert(std::is_nothrow_swappable_v
<int>, "");
80 static_assert(!std::is_nothrow_swappable_v
<void>, "");