File indexing completed on 2026-05-03 08:13:09
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___ALGORITHM_RANGES_COPY_N_H
0010 #define _LIBCPP___ALGORITHM_RANGES_COPY_N_H
0011
0012 #include <__algorithm/copy.h>
0013 #include <__algorithm/in_out_result.h>
0014 #include <__algorithm/iterator_operations.h>
0015 #include <__algorithm/ranges_copy.h>
0016 #include <__config>
0017 #include <__functional/identity.h>
0018 #include <__iterator/concepts.h>
0019 #include <__iterator/incrementable_traits.h>
0020 #include <__iterator/unreachable_sentinel.h>
0021 #include <__iterator/wrap_iter.h>
0022 #include <__utility/move.h>
0023
0024 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0025 # pragma GCC system_header
0026 #endif
0027
0028 _LIBCPP_PUSH_MACROS
0029 #include <__undef_macros>
0030
0031 _LIBCPP_BEGIN_NAMESPACE_STD
0032
0033 #if _LIBCPP_STD_VER >= 20
0034
0035 namespace ranges {
0036
0037 template <class _Ip, class _Op>
0038 using copy_n_result = in_out_result<_Ip, _Op>;
0039
0040
0041 struct __copy_n {
0042 template <class _InIter, class _DiffType, class _OutIter>
0043 _LIBCPP_HIDE_FROM_ABI constexpr static copy_n_result<_InIter, _OutIter>
0044 __go(_InIter __first, _DiffType __n, _OutIter __result) {
0045 while (__n != 0) {
0046 *__result = *__first;
0047 ++__first;
0048 ++__result;
0049 --__n;
0050 }
0051 return {std::move(__first), std::move(__result)};
0052 }
0053
0054 template <random_access_iterator _InIter, class _DiffType, random_access_iterator _OutIter>
0055 _LIBCPP_HIDE_FROM_ABI constexpr static copy_n_result<_InIter, _OutIter>
0056 __go(_InIter __first, _DiffType __n, _OutIter __result) {
0057 auto __ret = std::__copy(__first, __first + __n, __result);
0058 return {__ret.first, __ret.second};
0059 }
0060
0061 template <input_iterator _Ip, weakly_incrementable _Op>
0062 requires indirectly_copyable<_Ip, _Op>
0063 _LIBCPP_HIDE_FROM_ABI constexpr copy_n_result<_Ip, _Op>
0064 operator()(_Ip __first, iter_difference_t<_Ip> __n, _Op __result) const {
0065 return __go(std::move(__first), __n, std::move(__result));
0066 }
0067 };
0068
0069 inline namespace __cpo {
0070 inline constexpr auto copy_n = __copy_n{};
0071 }
0072 }
0073
0074 #endif
0075
0076 _LIBCPP_END_NAMESPACE_STD
0077
0078 _LIBCPP_POP_MACROS
0079
0080 #endif