]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/std/concepts/concepts.lang/concept.swappable/swappable_with.cc
1 // Copyright (C) 2019-2023 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-options "-std=gnu++2a" }
19 // { dg-do compile { target c++2a } }
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&> );
34 Immovable() = default;
35 Immovable(Immovable
&&) = delete;
38 static_assert( ! std::swappable_with
<N1::Immovable
&, N1::Immovable
&> );
44 Swappable() = default;
45 Swappable(Swappable
&&) = delete;
46 friend void swap(Swappable
&, Swappable
&) { }
49 static_assert( std::swappable_with
<N2::Swappable
&, N2::Swappable
&> );
56 friend void swap(Proxy
, Proxy
) { }
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
> );
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> );
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> );
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> );