2 //===----------------------------------------------------------------------===//
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
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___ITERATOR_ITER_MOVE_H
11 #define _LIBCPP___ITERATOR_ITER_MOVE_H
13 #include <__concepts/class_or_enum.h>
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>
22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23 # pragma GCC system_header
27 #include <__undef_macros>
29 _LIBCPP_BEGIN_NAMESPACE_STD
31 #if _LIBCPP_STD_VER >= 20
33 // [iterator.cust.move]
36 namespace __iter_move
{
38 void iter_move() = delete;
41 concept __unqualified_iter_move
= __class_or_enum
<remove_cvref_t
<_Tp
>> && requires(_Tp
&& __t
) {
42 // NOLINTNEXTLINE(libcpp-robust-against-adl) iter_swap ADL calls should only be made through ranges::iter_swap
43 iter_move(std::forward
<_Tp
>(__t
));
47 concept __move_deref
= !__unqualified_iter_move
<_Tp
> && requires(_Tp
&& __t
) {
49 requires is_lvalue_reference_v
<decltype(*__t
)>;
53 concept __just_deref
= !__unqualified_iter_move
<_Tp
> && !__move_deref
<_Tp
> && requires(_Tp
&& __t
) {
55 requires(!is_lvalue_reference_v
<decltype(*__t
)>);
58 // [iterator.cust.move]
61 // NOLINTBEGIN(libcpp-robust-against-adl) iter_move ADL calls should only be made through ranges::iter_move
63 requires __unqualified_iter_move
<_Ip
>
64 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr decltype(auto) operator()(_Ip
&& __i
) const
65 noexcept(noexcept(iter_move(std::forward
<_Ip
>(__i
)))) {
66 return iter_move(std::forward
<_Ip
>(__i
));
68 // NOLINTEND(libcpp-robust-against-adl)
71 requires __move_deref
<_Ip
>
72 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Ip
&& __i
) const
73 noexcept(noexcept(std::move(*std::forward
<_Ip
>(__i
)))) -> decltype(std::move(*std::forward
<_Ip
>(__i
))) {
74 return std::move(*std::forward
<_Ip
>(__i
));
78 requires __just_deref
<_Ip
>
79 [[nodiscard
]] _LIBCPP_HIDE_FROM_ABI
constexpr auto operator()(_Ip
&& __i
) const
80 noexcept(noexcept(*std::forward
<_Ip
>(__i
))) -> decltype(*std::forward
<_Ip
>(__i
)) {
81 return *std::forward
<_Ip
>(__i
);
84 } // namespace __iter_move
86 inline namespace __cpo
{
87 inline constexpr auto iter_move
= __iter_move::__fn
{};
91 template <__dereferenceable _Tp
>
92 requires
requires(_Tp
& __t
) {
93 { ranges::iter_move(__t
) } -> __can_reference
;
95 using iter_rvalue_reference_t
= decltype(ranges::iter_move(std::declval
<_Tp
&>()));
97 #endif // _LIBCPP_STD_VER >= 20
99 _LIBCPP_END_NAMESPACE_STD
103 #endif // _LIBCPP___ITERATOR_ITER_MOVE_H