14
14
#include < __algorithm/for_each_n_segment.h>
15
15
#include < __config>
16
16
#include < __functional/identity.h>
17
- #include < __functional/invoke.h>
18
17
#include < __iterator/iterator_traits.h>
18
+ #include < __iterator/next.h>
19
19
#include < __iterator/segmented_iterator.h>
20
20
#include < __type_traits/enable_if.h>
21
+ #include < __type_traits/invoke.h>
21
22
#include < __utility/convert_to_integral.h>
22
23
23
24
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -28,7 +29,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
28
29
29
30
template <class _InputIterator ,
30
31
class _Size ,
31
- class _Function ,
32
+ class _Func ,
32
33
class _Proj ,
33
34
__enable_if_t <!__has_random_access_iterator_category<_InputIterator>::value &&
34
35
(!__is_segmented_iterator<_InputIterator>::value
@@ -38,11 +39,11 @@ template <class _InputIterator,
38
39
// during SFINAE, which is a hard error to be fixed. Once fixed, we should uncomment.
39
40
int > = 0 >
40
41
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
41
- __for_each_n (_InputIterator __first, _Size __orig_n, _Function & __f, _Proj& __proj) {
42
+ __for_each_n (_InputIterator __first, _Size __orig_n, _Func & __f, _Proj& __proj) {
42
43
typedef decltype (std::__convert_to_integral (__orig_n)) _IntegralSize;
43
44
_IntegralSize __n = __orig_n;
44
45
while (__n > 0 ) {
45
- std::invoke (__f, std::invoke (__proj, *__first));
46
+ std::__invoke (__f, std::__invoke (__proj, *__first));
46
47
++__first;
47
48
--__n;
48
49
}
@@ -51,36 +52,36 @@ __for_each_n(_InputIterator __first, _Size __orig_n, _Function& __f, _Proj& __pr
51
52
52
53
template <class _RandIter ,
53
54
class _Size ,
54
- class _Function ,
55
+ class _Func ,
55
56
class _Proj ,
56
57
__enable_if_t <__has_random_access_iterator_category<_RandIter>::value, int > = 0 >
57
58
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandIter
58
- __for_each_n (_RandIter __first, _Size __orig_n, _Function & __f, _Proj& __proj) {
59
+ __for_each_n (_RandIter __first, _Size __orig_n, _Func & __f, _Proj& __proj) {
59
60
typedef decltype (std::__convert_to_integral (__orig_n)) _IntegralSize;
60
61
_IntegralSize __n = __orig_n;
61
- return std::__for_each (__first, __first + __n, __f, __proj);
62
+ return std::__for_each (__first, std::next ( __first, __n) , __f, __proj);
62
63
}
63
64
64
65
template <class _SegmentedIterator ,
65
66
class _Size ,
66
- class _Function ,
67
+ class _Func ,
67
68
class _Proj ,
68
69
__enable_if_t <!__has_random_access_iterator_category<_SegmentedIterator>::value &&
69
70
__is_segmented_iterator<_SegmentedIterator>::value &&
70
71
__has_random_access_iterator_category<
71
72
typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator>::value,
72
73
int > = 0 >
73
74
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _SegmentedIterator
74
- __for_each_n (_SegmentedIterator __first, _Size __orig_n, _Function & __f, _Proj& __proj ) {
75
+ __for_each_n (_SegmentedIterator __first, _Size __orig_n, _Func & __f, _Proj& __p ) {
75
76
return std::__for_each_n_segment (
76
- __first, __orig_n, std::__segment_processor<_SegmentedIterator, _Function , _Proj>(__f, __proj ));
77
+ __first, __orig_n, std::__segment_processor<_SegmentedIterator, _Func , _Proj>(__f, __p ));
77
78
}
78
79
79
80
#if _LIBCPP_STD_VER >= 17
80
81
81
- template <class _InputIterator , class _Size , class _Function >
82
+ template <class _InputIterator , class _Size , class _Func >
82
83
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
83
- for_each_n (_InputIterator __first, _Size __orig_n, _Function __f) {
84
+ for_each_n (_InputIterator __first, _Size __orig_n, _Func __f) {
84
85
__identity __proj;
85
86
return std::__for_each_n (__first, __orig_n, __f, __proj);
86
87
}
0 commit comments