]>
Commit | Line | Data |
---|---|---|
a945c346 | 1 | // Copyright (C) 2019-2024 Free Software Foundation, Inc. |
cfc219ae JW |
2 | // |
3 | // This file is part of the GNU ISO C++ Library. This library is free | |
4 | // software; you can redistribute it and/or modify it under the | |
5 | // terms of the GNU General Public License as published by the | |
6 | // Free Software Foundation; either version 3, or (at your option) | |
7 | // any later version. | |
8 | ||
9 | // This library is distributed in the hope that it will be useful, | |
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | // GNU General Public License for more details. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
d4ac20b0 | 18 | // { dg-do compile { target c++20 } } |
cfc219ae JW |
19 | |
20 | #include <concepts> | |
21 | ||
22 | static_assert( std::swappable_with<int&, int&> ); | |
23 | static_assert( ! std::swappable_with<int, int> ); | |
24 | static_assert( ! std::swappable_with<int*, int*> ); | |
25 | static_assert( ! std::swappable_with<int&, const int&> ); | |
26 | static_assert( ! std::swappable_with<const int&, const int&> ); | |
27 | static_assert( ! std::swappable_with<int&, long&> ); | |
28 | ||
29 | namespace N1 | |
30 | { | |
31 | struct Immovable | |
32 | { | |
33 | Immovable() = default; | |
34 | Immovable(Immovable&&) = delete; | |
35 | }; | |
36 | } | |
37 | static_assert( ! std::swappable_with<N1::Immovable&, N1::Immovable&> ); | |
38 | ||
39 | namespace N2 | |
40 | { | |
41 | struct Swappable | |
42 | { | |
43 | Swappable() = default; | |
44 | Swappable(Swappable&&) = delete; | |
45 | friend void swap(Swappable&, Swappable&) { } | |
46 | }; | |
47 | } | |
48 | static_assert( std::swappable_with<N2::Swappable&, N2::Swappable&> ); | |
49 | ||
50 | namespace N3 | |
51 | { | |
52 | struct A { }; | |
53 | struct Proxy { | |
54 | Proxy(A&) { } | |
55 | friend void swap(Proxy, Proxy) { } | |
56 | }; | |
57 | } | |
58 | ||
59 | static_assert( std::swappable_with<N3::A&, N3::A&> ); | |
60 | static_assert( std::swappable_with<N3::A&, N3::Proxy> ); | |
61 | static_assert( std::swappable_with<N3::Proxy, N3::A&> ); | |
62 | static_assert( std::swappable_with<N3::Proxy, N3::Proxy> ); | |
63 | ||
64 | struct C { C(int&) { } }; | |
65 | void swap(int&, C&) { } // not symmetrical | |
66 | static_assert( ! std::swappable_with<int, C> ); | |
67 | static_assert( ! std::swappable_with<C, int> ); | |
68 | ||
69 | struct D { D(int&) { } }; | |
70 | void swap(int&, D&) { } | |
71 | void swap(D&&, int&) { } // only accepts rvalues | |
72 | static_assert( ! std::swappable_with<int&, D> ); | |
73 | static_assert( ! std::swappable_with<D, int> ); | |
74 | ||
75 | struct E { E(int&) { } }; | |
76 | void swap(int, E&&) { } // only accepts rvalues | |
77 | void swap(E&, int) { } | |
78 | static_assert( ! std::swappable_with<int, E> ); | |
79 | static_assert( ! std::swappable_with<E, int> ); |