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