| 1 | // Copyright (C) 2020-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 compile { target c++20 } } |
| 19 | |
| 20 | #include <iterator> |
| 21 | |
| 22 | template<typename T> |
| 23 | struct Dereferenceable { T operator*(); }; |
| 24 | |
| 25 | template<typename T> |
| 26 | concept has_iter_reference |
| 27 | = requires { typename std::iter_reference_t<T>; }; |
| 28 | |
| 29 | template<typename T, typename U> |
| 30 | concept is_iter_reference_for |
| 31 | = has_iter_reference<U> && std::same_as<T, std::iter_reference_t<U>>; |
| 32 | |
| 33 | static_assert(!has_iter_reference<Dereferenceable<void>>); |
| 34 | static_assert(is_iter_reference_for<int, Dereferenceable<int>>); |
| 35 | static_assert(is_iter_reference_for<int&, Dereferenceable<int&>>); |
| 36 | static_assert(is_iter_reference_for<int&&, Dereferenceable<int&&>>); |
| 37 | static_assert(is_iter_reference_for<int&, int*>); |
| 38 | static_assert(is_iter_reference_for<const int&, const int*>); |
| 39 | |
| 40 | template<typename T> |
| 41 | concept has_iter_rvalue_reference |
| 42 | = requires { typename std::iter_rvalue_reference_t<T>; }; |
| 43 | |
| 44 | template<typename T, typename U> |
| 45 | concept is_iter_rvalue_reference_for |
| 46 | = has_iter_rvalue_reference<U> |
| 47 | && std::same_as<T, std::iter_rvalue_reference_t<U>>; |
| 48 | |
| 49 | static_assert(!has_iter_rvalue_reference<Dereferenceable<void>>); |
| 50 | static_assert(is_iter_rvalue_reference_for<int, Dereferenceable<int>>); |
| 51 | static_assert(is_iter_rvalue_reference_for<int&&, Dereferenceable<int&>>); |
| 52 | static_assert(is_iter_rvalue_reference_for<int&&, Dereferenceable<int&&>>); |
| 53 | static_assert(is_iter_rvalue_reference_for<int&&, int*>); |
| 54 | static_assert(is_iter_rvalue_reference_for<const int&&, const int*>); |
| 55 | |
| 56 | // These functions should be found by ADL. std::move is not applied to result. |
| 57 | long iter_move(Dereferenceable<short>); |
| 58 | long& iter_move(Dereferenceable<short&&>); |
| 59 | static_assert(is_iter_rvalue_reference_for<long, Dereferenceable<short>>); |
| 60 | static_assert(is_iter_rvalue_reference_for<long&, Dereferenceable<short&&>>); |