// Copyright (C) 2019-2025 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING3. If not see // . // { dg-do compile { target c++20 } } #include static_assert( std::swappable_with ); static_assert( ! std::swappable_with ); static_assert( ! std::swappable_with ); static_assert( ! std::swappable_with ); static_assert( ! std::swappable_with ); static_assert( ! std::swappable_with ); namespace N1 { struct Immovable { Immovable() = default; Immovable(Immovable&&) = delete; }; } static_assert( ! std::swappable_with ); namespace N2 { struct Swappable { Swappable() = default; Swappable(Swappable&&) = delete; friend void swap(Swappable&, Swappable&) { } }; } static_assert( std::swappable_with ); namespace N3 { struct A { }; struct Proxy { Proxy(A&) { } friend void swap(Proxy, Proxy) { } }; } static_assert( std::swappable_with ); static_assert( std::swappable_with ); static_assert( std::swappable_with ); static_assert( std::swappable_with ); struct C { C(int&) { } }; void swap(int&, C&) { } // not symmetrical static_assert( ! std::swappable_with ); static_assert( ! std::swappable_with ); struct D { D(int&) { } }; void swap(int&, D&) { } void swap(D&&, int&) { } // only accepts rvalues static_assert( ! std::swappable_with ); static_assert( ! std::swappable_with ); struct E { E(int&) { } }; void swap(int, E&&) { } // only accepts rvalues void swap(E&, int) { } static_assert( ! std::swappable_with ); static_assert( ! std::swappable_with );