1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___CXX03___ALGORITHM_RANGES_COPY_N_H
10 #define _LIBCPP___CXX03___ALGORITHM_RANGES_COPY_N_H
12 #include <__cxx03/__algorithm/copy.h>
13 #include <__cxx03/__algorithm/in_out_result.h>
14 #include <__cxx03/__algorithm/iterator_operations.h>
15 #include <__cxx03/__algorithm/ranges_copy.h>
16 #include <__cxx03/__config>
17 #include <__cxx03/__functional/identity.h>
18 #include <__cxx03/__iterator/concepts.h>
19 #include <__cxx03/__iterator/incrementable_traits.h>
20 #include <__cxx03/__iterator/unreachable_sentinel.h>
21 #include <__cxx03/__iterator/wrap_iter.h>
22 #include <__cxx03/__utility/move.h>
24 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25 # pragma GCC system_header
29 #include <__cxx03/__undef_macros>
31 _LIBCPP_BEGIN_NAMESPACE_STD
33 #if _LIBCPP_STD_VER >= 20
37 template <class _Ip
, class _Op
>
38 using copy_n_result
= in_out_result
<_Ip
, _Op
>;
42 template <class _InIter
, class _DiffType
, class _OutIter
>
43 _LIBCPP_HIDE_FROM_ABI
constexpr static copy_n_result
<_InIter
, _OutIter
>
44 __go(_InIter __first
, _DiffType __n
, _OutIter __result
) {
51 return {std::move(__first
), std::move(__result
)};
54 template <random_access_iterator _InIter
, class _DiffType
, random_access_iterator _OutIter
>
55 _LIBCPP_HIDE_FROM_ABI
constexpr static copy_n_result
<_InIter
, _OutIter
>
56 __go(_InIter __first
, _DiffType __n
, _OutIter __result
) {
57 auto __ret
= std::__copy
<_RangeAlgPolicy
>(__first
, __first
+ __n
, __result
);
58 return {__ret
.first
, __ret
.second
};
61 template <input_iterator _Ip
, weakly_incrementable _Op
>
62 requires indirectly_copyable
<_Ip
, _Op
>
63 _LIBCPP_HIDE_FROM_ABI
constexpr copy_n_result
<_Ip
, _Op
>
64 operator()(_Ip __first
, iter_difference_t
<_Ip
> __n
, _Op __result
) const {
65 return __go(std::move(__first
), __n
, std::move(__result
));
68 } // namespace __copy_n
70 inline namespace __cpo
{
71 inline constexpr auto copy_n
= __copy_n::__fn
{};
75 #endif // _LIBCPP_STD_VER >= 20
77 _LIBCPP_END_NAMESPACE_STD
81 #endif // _LIBCPP___CXX03___ALGORITHM_RANGES_COPY_N_H