]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swappable_with.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / std / concepts / concepts.lang / concept.swappable / swappable_with.cc
1 // Copyright (C) 2019-2023 Free Software Foundation, Inc.
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
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
20
21 #include <concepts>
22
23 static_assert( std::swappable_with<int&, int&> );
24 static_assert( ! std::swappable_with<int, int> );
25 static_assert( ! std::swappable_with<int*, int*> );
26 static_assert( ! std::swappable_with<int&, const int&> );
27 static_assert( ! std::swappable_with<const int&, const int&> );
28 static_assert( ! std::swappable_with<int&, long&> );
29
30 namespace N1
31 {
32 struct Immovable
33 {
34 Immovable() = default;
35 Immovable(Immovable&&) = delete;
36 };
37 }
38 static_assert( ! std::swappable_with<N1::Immovable&, N1::Immovable&> );
39
40 namespace N2
41 {
42 struct Swappable
43 {
44 Swappable() = default;
45 Swappable(Swappable&&) = delete;
46 friend void swap(Swappable&, Swappable&) { }
47 };
48 }
49 static_assert( std::swappable_with<N2::Swappable&, N2::Swappable&> );
50
51 namespace N3
52 {
53 struct A { };
54 struct Proxy {
55 Proxy(A&) { }
56 friend void swap(Proxy, Proxy) { }
57 };
58 }
59
60 static_assert( std::swappable_with<N3::A&, N3::A&> );
61 static_assert( std::swappable_with<N3::A&, N3::Proxy> );
62 static_assert( std::swappable_with<N3::Proxy, N3::A&> );
63 static_assert( std::swappable_with<N3::Proxy, N3::Proxy> );
64
65 struct C { C(int&) { } };
66 void swap(int&, C&) { } // not symmetrical
67 static_assert( ! std::swappable_with<int, C> );
68 static_assert( ! std::swappable_with<C, int> );
69
70 struct D { D(int&) { } };
71 void swap(int&, D&) { }
72 void swap(D&&, int&) { } // only accepts rvalues
73 static_assert( ! std::swappable_with<int&, D> );
74 static_assert( ! std::swappable_with<D, int> );
75
76 struct E { E(int&) { } };
77 void swap(int, E&&) { } // only accepts rvalues
78 void swap(E&, int) { }
79 static_assert( ! std::swappable_with<int, E> );
80 static_assert( ! std::swappable_with<E, int> );