]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/is_swappable_with/value.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / is_swappable_with / value.cc
1 // { dg-do compile { target c++17 } }
2
3 // Copyright (C) 2016-2023 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 #include <type_traits>
21 #include <testsuite_tr1.h>
22
23 #ifndef __cpp_lib_is_swappable
24 # error "Feature-test macro for is_swappable_with missing"
25 #elif __cpp_lib_is_swappable != 201603
26 # error "Feature-test macro for is_swappable_with has wrong value"
27 #endif
28
29 namespace funny {
30 struct T0 {};
31
32 void swap(T0, T0);
33
34 struct T1 {};
35 struct T2 {};
36
37 void swap(T1, T2);
38 void swap(T2, T1);
39
40 struct BoolLike {};
41
42 void swap(BoolLike, bool&);
43 void swap(bool&, BoolLike);
44
45 struct F0 {};
46
47 void swap(F0, F0) = delete;
48
49 struct F1 {};
50
51 void swap(F0, F1) = delete;
52 void swap(F1, F0) = delete;
53
54 struct F2 {};
55 struct F3 {};
56
57 void swap(F2, F3);
58 void swap(F3, F2) = delete;
59
60 struct F4
61 {
62 friend void swap(F4, F4) = delete;
63 };
64 }
65
66 void test01()
67 {
68 using std::is_swappable_with;
69 using namespace __gnu_test;
70 // Positive tests.
71 static_assert(test_property<is_swappable_with, int&, int&>(true), "");
72 static_assert(test_property<is_swappable_with, funny::T0,
73 funny::T0>(true), "");
74 static_assert(test_property<is_swappable_with, funny::T0,
75 const funny::T0>(true), "");
76 static_assert(test_property<is_swappable_with, funny::T1,
77 funny::T2>(true), "");
78 static_assert(test_property<is_swappable_with, funny::T2,
79 funny::T1>(true), "");
80 static_assert(test_property<is_swappable_with, funny::BoolLike,
81 bool&>(true), "");
82 static_assert(test_property<is_swappable_with, const funny::BoolLike,
83 bool&>(true), "");
84
85 // Negative tests.
86 static_assert(test_property<is_swappable_with, int, int>(false), "");
87 static_assert(test_property<is_swappable_with, int&, unsigned&>(false), "");
88 static_assert(test_property<is_swappable_with, const int&,
89 const int&>(false), "");
90 static_assert(test_property<is_swappable_with, funny::F0,
91 funny::F0>(false), "");
92 static_assert(test_property<is_swappable_with, funny::F0,
93 const funny::F0>(false), "");
94 static_assert(test_property<is_swappable_with, funny::T0,
95 funny::T1>(false), "");
96 static_assert(test_property<is_swappable_with, funny::F0,
97 funny::F1>(false), "");
98 static_assert(test_property<is_swappable_with, funny::F0,
99 const funny::F1>(false), "");
100 static_assert(test_property<is_swappable_with, const funny::F0,
101 funny::F1>(false), "");
102 static_assert(test_property<is_swappable_with, funny::F2,
103 funny::F3>(false), "");
104 static_assert(test_property<is_swappable_with, funny::F2,
105 const funny::F3>(false), "");
106 static_assert(test_property<is_swappable_with, const funny::F2,
107 funny::F3>(false), "");
108 static_assert(test_property<is_swappable_with, funny::F4,
109 funny::F4>(false), "");
110 static_assert(test_property<is_swappable_with, funny::BoolLike,
111 funny::BoolLike>(false), "");
112 }