blob: 43a0a4fe46b1191598f8c3cbb2c90816c8063732 [file] [log] [blame]
Eric Fiselier8f1e73d2016-04-21 23:38:59 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// UNSUPPORTED: c++98, c++03, c++11, c++14
11
12// type_traits
13
14// is_swappable
15
16#include <type_traits>
17#include <utility>
18#include <vector>
19#include "test_macros.h"
20
21namespace MyNS {
22
23// Make the test types non-copyable so that generic std::swap is not valid.
24struct A {
25 A(A const&) = delete;
26 A& operator=(A const&) = delete;
27};
28
29struct B {
30 B(B const&) = delete;
31 B& operator=(B const&) = delete;
32};
33
34struct C {};
35struct D {};
36
37void swap(A&, A&) {}
38
39void swap(A&, B&) {}
40void swap(B&, A&) {}
41
42void swap(A&, C&) {} // missing swap(C, A)
43void swap(D&, C&) {}
44
45struct M {
46 M(M const&) = delete;
47 M& operator=(M const&) = delete;
48};
49
50void swap(M&&, M&&) {}
51
52} // namespace MyNS
53
54int main()
55{
56 using namespace MyNS;
57 {
58 // Test that is_swappable applies an lvalue reference to the type.
59 static_assert(std::is_swappable<A>::value, "");
60 static_assert(std::is_swappable<A&>::value, "");
61 static_assert(!std::is_swappable<M>::value, "");
62 static_assert(!std::is_swappable<M&&>::value, "");
63 }
64 static_assert(!std::is_swappable<B>::value, "");
65 static_assert(std::is_swappable<C>::value, "");
66 {
67 // test non-referencable types
68 static_assert(!std::is_swappable<void>::value, "");
69 static_assert(!std::is_swappable<int() const>::value, "");
70 static_assert(!std::is_swappable<int() &>::value, "");
71 }
72 {
73 // test for presense of is_swappable_v
74 static_assert(std::is_swappable_v<int>);
75 static_assert(!std::is_swappable_v<M>);
76 }
77}