| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H |
| 10 | #define _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H |
| 11 | |
| 12 | #include <__algorithm/for_each_n.h> |
| 13 | #include <__algorithm/in_fun_result.h> |
| 14 | #include <__config> |
| 15 | #include <__functional/identity.h> |
| 16 | #include <__iterator/concepts.h> |
| 17 | #include <__iterator/incrementable_traits.h> |
| 18 | #include <__iterator/iterator_traits.h> |
| 19 | #include <__iterator/projected.h> |
| 20 | #include <__ranges/concepts.h> |
| 21 | #include <__utility/move.h> |
| 22 | |
| 23 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 24 | # pragma GCC system_header |
| 25 | #endif |
| 26 | |
| 27 | _LIBCPP_PUSH_MACROS |
| 28 | #include <__undef_macros> |
| 29 | |
| 30 | #if _LIBCPP_STD_VER >= 20 |
| 31 | |
| 32 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 33 | |
| 34 | namespace ranges { |
| 35 | |
| 36 | template <class _Iter, class _Func> |
| 37 | using for_each_n_result = in_fun_result<_Iter, _Func>; |
| 38 | |
| 39 | struct __for_each_n { |
| 40 | template <input_iterator _Iter, class _Proj = identity, indirectly_unary_invocable<projected<_Iter, _Proj>> _Func> |
| 41 | _LIBCPP_HIDE_FROM_ABI constexpr for_each_n_result<_Iter, _Func> |
| 42 | operator()(_Iter __first, iter_difference_t<_Iter> __count, _Func __func, _Proj __proj = {}) const { |
| 43 | auto __last = std::__for_each_n(std::move(__first), __count, __func, __proj); |
| 44 | return {std::move(__last), std::move(__func)}; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | inline namespace __cpo { |
| 49 | inline constexpr auto for_each_n = __for_each_n{}; |
| 50 | } // namespace __cpo |
| 51 | } // namespace ranges |
| 52 | |
| 53 | _LIBCPP_END_NAMESPACE_STD |
| 54 | |
| 55 | #endif // _LIBCPP_STD_VER >= 20 |
| 56 | |
| 57 | _LIBCPP_POP_MACROS |
| 58 | |
| 59 | #endif // _LIBCPP___ALGORITHM_RANGES_FOR_EACH_N_H |