]> git.ipfire.org Git - thirdparty/gcc.git/blame - 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
CommitLineData
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
22static_assert( std::swappable_with<int&, int&> );
23static_assert( ! std::swappable_with<int, int> );
24static_assert( ! std::swappable_with<int*, int*> );
25static_assert( ! std::swappable_with<int&, const int&> );
26static_assert( ! std::swappable_with<const int&, const int&> );
27static_assert( ! std::swappable_with<int&, long&> );
28
29namespace N1
30{
31 struct Immovable
32 {
33 Immovable() = default;
34 Immovable(Immovable&&) = delete;
35 };
36}
37static_assert( ! std::swappable_with<N1::Immovable&, N1::Immovable&> );
38
39namespace N2
40{
41 struct Swappable
42 {
43 Swappable() = default;
44 Swappable(Swappable&&) = delete;
45 friend void swap(Swappable&, Swappable&) { }
46 };
47}
48static_assert( std::swappable_with<N2::Swappable&, N2::Swappable&> );
49
50namespace N3
51{
52 struct A { };
53 struct Proxy {
54 Proxy(A&) { }
55 friend void swap(Proxy, Proxy) { }
56 };
57}
58
59static_assert( std::swappable_with<N3::A&, N3::A&> );
60static_assert( std::swappable_with<N3::A&, N3::Proxy> );
61static_assert( std::swappable_with<N3::Proxy, N3::A&> );
62static_assert( std::swappable_with<N3::Proxy, N3::Proxy> );
63
64struct C { C(int&) { } };
65void swap(int&, C&) { } // not symmetrical
66static_assert( ! std::swappable_with<int, C> );
67static_assert( ! std::swappable_with<C, int> );
68
69struct D { D(int&) { } };
70void swap(int&, D&) { }
71void swap(D&&, int&) { } // only accepts rvalues
72static_assert( ! std::swappable_with<int&, D> );
73static_assert( ! std::swappable_with<D, int> );
74
75struct E { E(int&) { } };
76void swap(int, E&&) { } // only accepts rvalues
77void swap(E&, int) { }
78static_assert( ! std::swappable_with<int, E> );
79static_assert( ! std::swappable_with<E, int> );