Yi Kong | 8328301 | 2023-12-13 12:57:00 +0900 | [diff] [blame^] | 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___ITERATOR_ITER_MOVE_H |
| 11 | #define _LIBCPP___ITERATOR_ITER_MOVE_H |
| 12 | |
| 13 | #include <__concepts/class_or_enum.h> |
| 14 | #include <__config> |
| 15 | #include <__iterator/iterator_traits.h> |
| 16 | #include <__type_traits/is_reference.h> |
| 17 | #include <__type_traits/remove_cvref.h> |
| 18 | #include <__utility/declval.h> |
| 19 | #include <__utility/forward.h> |
| 20 | #include <__utility/move.h> |
| 21 | |
| 22 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 23 | # pragma GCC system_header |
| 24 | #endif |
| 25 | |
| 26 | _LIBCPP_PUSH_MACROS |
| 27 | #include <__undef_macros> |
| 28 | |
| 29 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 30 | |
| 31 | #if _LIBCPP_STD_VER >= 20 |
| 32 | |
| 33 | // [iterator.cust.move] |
| 34 | |
| 35 | namespace ranges { |
| 36 | namespace __iter_move { |
| 37 | |
| 38 | void iter_move(); |
| 39 | |
| 40 | template <class _Tp> |
| 41 | concept __unqualified_iter_move = |
| 42 | __class_or_enum<remove_cvref_t<_Tp>> && |
| 43 | requires (_Tp&& __t) { |
| 44 | // NOLINTNEXTLINE(libcpp-robust-against-adl) iter_swap ADL calls should only be made through ranges::iter_swap |
| 45 | iter_move(std::forward<_Tp>(__t)); |
| 46 | }; |
| 47 | |
| 48 | template<class _Tp> |
| 49 | concept __move_deref = |
| 50 | !__unqualified_iter_move<_Tp> && |
| 51 | requires (_Tp&& __t) { |
| 52 | *__t; |
| 53 | requires is_lvalue_reference_v<decltype(*__t)>; |
| 54 | }; |
| 55 | |
| 56 | template<class _Tp> |
| 57 | concept __just_deref = |
| 58 | !__unqualified_iter_move<_Tp> && |
| 59 | !__move_deref<_Tp> && |
| 60 | requires (_Tp&& __t) { |
| 61 | *__t; |
| 62 | requires (!is_lvalue_reference_v<decltype(*__t)>); |
| 63 | }; |
| 64 | |
| 65 | // [iterator.cust.move] |
| 66 | |
| 67 | struct __fn { |
| 68 | // NOLINTBEGIN(libcpp-robust-against-adl) iter_move ADL calls should only be made through ranges::iter_move |
| 69 | template<class _Ip> |
| 70 | requires __unqualified_iter_move<_Ip> |
| 71 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr decltype(auto) operator()(_Ip&& __i) const |
| 72 | noexcept(noexcept(iter_move(std::forward<_Ip>(__i)))) |
| 73 | { |
| 74 | return iter_move(std::forward<_Ip>(__i)); |
| 75 | } |
| 76 | // NOLINTEND(libcpp-robust-against-adl) |
| 77 | |
| 78 | template<class _Ip> |
| 79 | requires __move_deref<_Ip> |
| 80 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Ip&& __i) const |
| 81 | noexcept(noexcept(std::move(*std::forward<_Ip>(__i)))) |
| 82 | -> decltype( std::move(*std::forward<_Ip>(__i))) |
| 83 | { return std::move(*std::forward<_Ip>(__i)); } |
| 84 | |
| 85 | template<class _Ip> |
| 86 | requires __just_deref<_Ip> |
| 87 | [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Ip&& __i) const |
| 88 | noexcept(noexcept(*std::forward<_Ip>(__i))) |
| 89 | -> decltype( *std::forward<_Ip>(__i)) |
| 90 | { return *std::forward<_Ip>(__i); } |
| 91 | }; |
| 92 | } // namespace __iter_move |
| 93 | |
| 94 | inline namespace __cpo { |
| 95 | inline constexpr auto iter_move = __iter_move::__fn{}; |
| 96 | } // namespace __cpo |
| 97 | } // namespace ranges |
| 98 | |
| 99 | template<__dereferenceable _Tp> |
| 100 | requires requires(_Tp& __t) { { ranges::iter_move(__t) } -> __can_reference; } |
| 101 | using iter_rvalue_reference_t = decltype(ranges::iter_move(std::declval<_Tp&>())); |
| 102 | |
| 103 | #endif // _LIBCPP_STD_VER >= 20 |
| 104 | |
| 105 | _LIBCPP_END_NAMESPACE_STD |
| 106 | |
| 107 | _LIBCPP_POP_MACROS |
| 108 | |
| 109 | #endif // _LIBCPP___ITERATOR_ITER_MOVE_H |