File indexing completed on 2026-05-03 08:13:10
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
0010 #define _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H
0011
0012 #include <__algorithm/in_fun_result.h>
0013 #include <__config>
0014 #include <__functional/identity.h>
0015 #include <__functional/invoke.h>
0016 #include <__iterator/concepts.h>
0017 #include <__iterator/incrementable_traits.h>
0018 #include <__iterator/iterator_traits.h>
0019 #include <__iterator/projected.h>
0020 #include <__ranges/concepts.h>
0021 #include <__utility/move.h>
0022
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 # pragma GCC system_header
0025 #endif
0026
0027 _LIBCPP_PUSH_MACROS
0028 #include <__undef_macros>
0029
0030 #if _LIBCPP_STD_VER >= 20
0031
0032 _LIBCPP_BEGIN_NAMESPACE_STD
0033
0034 namespace ranges {
0035
0036 template <class _Iter, class _Func>
0037 using for_each_n_result = in_fun_result<_Iter, _Func>;
0038
0039 struct __for_each_n {
0040 template <input_iterator _Iter, class _Proj = identity, indirectly_unary_invocable<projected<_Iter, _Proj>> _Func>
0041 _LIBCPP_HIDE_FROM_ABI constexpr for_each_n_result<_Iter, _Func>
0042 operator()(_Iter __first, iter_difference_t<_Iter> __count, _Func __func, _Proj __proj = {}) const {
0043 while (__count-- > 0) {
0044 std::invoke(__func, std::invoke(__proj, *__first));
0045 ++__first;
0046 }
0047 return {std::move(__first), std::move(__func)};
0048 }
0049 };
0050
0051 inline namespace __cpo {
0052 inline constexpr auto for_each_n = __for_each_n{};
0053 }
0054 }
0055
0056 _LIBCPP_END_NAMESPACE_STD
0057
0058 #endif
0059
0060 _LIBCPP_POP_MACROS
0061
0062 #endif