| 1 | // Copyright (C) 2019-2025 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-do run { target c++20 } } |
| 19 | |
| 20 | #include <iterator> |
| 21 | #include <testsuite_hooks.h> |
| 22 | #include <testsuite_iterators.h> |
| 23 | |
| 24 | static_assert(__gnu_test::is_customization_point_object(std::ranges::iter_swap)); |
| 25 | |
| 26 | struct X |
| 27 | { |
| 28 | int value; |
| 29 | |
| 30 | constexpr X(int i) : value(i) { } |
| 31 | |
| 32 | X(const X&) = default; |
| 33 | X& operator=(const X&) = default; |
| 34 | |
| 35 | constexpr X& operator=(X&& x) |
| 36 | { |
| 37 | value = x.value; |
| 38 | x.value = -1; |
| 39 | return *this; |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | constexpr bool |
| 44 | test_X(int i, int j) |
| 45 | { |
| 46 | X x1{i}, x2{j}; |
| 47 | std::ranges::iter_swap(&x1, &x2); |
| 48 | return x1.value == j && x2.value == i; |
| 49 | } |
| 50 | |
| 51 | static_assert( test_X(1, 2) ); |
| 52 | |
| 53 | void |
| 54 | test01() |
| 55 | { |
| 56 | VERIFY( test_X(3, 4) ); |
| 57 | } |
| 58 | |
| 59 | int |
| 60 | main() |
| 61 | { |
| 62 | test01(); |
| 63 | } |