Skip to content

Commit d14bde4

Browse files
committed
Fix invoke call and add projection
1 parent d1bb4a4 commit d14bde4

File tree

5 files changed

+32
-36
lines changed

5 files changed

+32
-36
lines changed

libcxx/include/__algorithm/for_each.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
#include <__algorithm/for_each_segment.h>
1414
#include <__config>
1515
#include <__functional/identity.h>
16-
#include <__functional/invoke.h>
1716
#include <__iterator/segmented_iterator.h>
1817
#include <__type_traits/enable_if.h>
18+
#include <__type_traits/invoke.h>
1919
#include <__utility/move.h>
2020

2121
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -27,46 +27,46 @@ _LIBCPP_PUSH_MACROS
2727

2828
_LIBCPP_BEGIN_NAMESPACE_STD
2929

30-
template <class _InputIterator, class _Sent, class _Function, class _Proj>
30+
template <class _InputIterator, class _Sent, class _Func, class _Proj>
3131
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
32-
__for_each(_InputIterator __first, _Sent __last, _Function& __f, _Proj& __proj) {
32+
__for_each(_InputIterator __first, _Sent __last, _Func& __f, _Proj& __proj) {
3333
for (; __first != __last; ++__first)
34-
std::invoke(__f, std::invoke(__proj, *__first));
34+
std::__invoke(__f, std::__invoke(__proj, *__first));
3535
return __first;
3636
}
3737

38-
// __segment_processor handles the per-segment processing by applying the user-provided function to each element
39-
// within the segment. It acts as a functor passed to the segmented iterator algorithm __for_each_segment.
40-
template <class _SegmentedIterator, class _Function, class _Proj>
38+
// __segment_processor handles the per-segment processing by applying the function object __func_ to the
39+
// projected value of each element within the segment. It serves as a functor utilized by the segmented
40+
// iterator algorithms such as __for_each_segment and __for_each_n_segment.
41+
template <class _SegmentedIterator, class _Func, class _Proj>
4142
struct __segment_processor {
4243
using _Traits _LIBCPP_NODEBUG = __segmented_iterator_traits<_SegmentedIterator>;
4344

44-
_Function& __func_;
45+
_Func& __func_;
4546
_Proj& __proj_;
4647

47-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __segment_processor(_Function& __func, _Proj& __proj)
48-
: __func_(__func), __proj_(__proj) {}
48+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __segment_processor(_Func& __f, _Proj& __p)
49+
: __func_(__f), __proj_(__p) {}
4950

50-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
51+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
5152
operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
5253
std::__for_each(__lfirst, __llast, __func_, __proj_);
5354
}
5455
};
5556

5657
template <class _SegmentedIterator,
57-
class _Function,
58+
class _Func,
5859
class _Proj,
5960
__enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0>
6061
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator
61-
__for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Function& __func, _Proj& __proj) {
62-
std::__for_each_segment(
63-
__first, __last, std::__segment_processor<_SegmentedIterator, _Function, _Proj>(__func, __proj));
62+
__for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Func& __f, _Proj& __p) {
63+
std::__for_each_segment(__first, __last, std::__segment_processor<_SegmentedIterator, _Func, _Proj>(__f, __p));
6464
return __last;
6565
}
6666

67-
template <class _InputIterator, class _Function>
68-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function
69-
for_each(_InputIterator __first, _InputIterator __last, _Function __f) {
67+
template <class _InputIterator, class _Func>
68+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Func
69+
for_each(_InputIterator __first, _InputIterator __last, _Func __f) {
7070
__identity __proj;
7171
std::__for_each(__first, __last, __f, __proj);
7272
return std::move(__f);

libcxx/include/__algorithm/for_each_n.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
#include <__algorithm/for_each_n_segment.h>
1515
#include <__config>
1616
#include <__functional/identity.h>
17-
#include <__functional/invoke.h>
1817
#include <__iterator/iterator_traits.h>
1918
#include <__iterator/segmented_iterator.h>
2019
#include <__type_traits/enable_if.h>
20+
#include <__type_traits/invoke.h>
2121
#include <__utility/convert_to_integral.h>
2222

2323
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
@@ -28,7 +28,7 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2828

2929
template <class _InputIterator,
3030
class _Size,
31-
class _Function,
31+
class _Func,
3232
class _Proj,
3333
__enable_if_t<!__has_random_access_iterator_category<_InputIterator>::value &&
3434
(!__is_segmented_iterator<_InputIterator>::value
@@ -38,11 +38,11 @@ template <class _InputIterator,
3838
// during SFINAE, which is a hard error to be fixed. Once fixed, we should uncomment.
3939
int> = 0>
4040
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
41-
__for_each_n(_InputIterator __first, _Size __orig_n, _Function& __f, _Proj& __proj) {
41+
__for_each_n(_InputIterator __first, _Size __orig_n, _Func& __f, _Proj& __proj) {
4242
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
4343
_IntegralSize __n = __orig_n;
4444
while (__n > 0) {
45-
std::invoke(__f, std::invoke(__proj, *__first));
45+
std::__invoke(__f, std::__invoke(__proj, *__first));
4646
++__first;
4747
--__n;
4848
}
@@ -51,36 +51,36 @@ __for_each_n(_InputIterator __first, _Size __orig_n, _Function& __f, _Proj& __pr
5151

5252
template <class _RandIter,
5353
class _Size,
54-
class _Function,
54+
class _Func,
5555
class _Proj,
5656
__enable_if_t<__has_random_access_iterator_category<_RandIter>::value, int> = 0>
5757
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandIter
58-
__for_each_n(_RandIter __first, _Size __orig_n, _Function& __f, _Proj& __proj) {
58+
__for_each_n(_RandIter __first, _Size __orig_n, _Func& __f, _Proj& __proj) {
5959
typedef decltype(std::__convert_to_integral(__orig_n)) _IntegralSize;
6060
_IntegralSize __n = __orig_n;
6161
return std::__for_each(__first, __first + __n, __f, __proj);
6262
}
6363

6464
template <class _SegmentedIterator,
6565
class _Size,
66-
class _Function,
66+
class _Func,
6767
class _Proj,
6868
__enable_if_t<!__has_random_access_iterator_category<_SegmentedIterator>::value &&
6969
__is_segmented_iterator<_SegmentedIterator>::value &&
7070
__has_random_access_iterator_category<
7171
typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator>::value,
7272
int> = 0>
7373
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _SegmentedIterator
74-
__for_each_n(_SegmentedIterator __first, _Size __orig_n, _Function& __f, _Proj& __proj) {
74+
__for_each_n(_SegmentedIterator __first, _Size __orig_n, _Func& __f, _Proj& __p) {
7575
return std::__for_each_n_segment(
76-
__first, __orig_n, std::__segment_processor<_SegmentedIterator, _Function, _Proj>(__f, __proj));
76+
__first, __orig_n, std::__segment_processor<_SegmentedIterator, _Func, _Proj>(__f, __p));
7777
}
7878

7979
#if _LIBCPP_STD_VER >= 17
8080

81-
template <class _InputIterator, class _Size, class _Function>
81+
template <class _InputIterator, class _Size, class _Func>
8282
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _InputIterator
83-
for_each_n(_InputIterator __first, _Size __orig_n, _Function __f) {
83+
for_each_n(_InputIterator __first, _Size __orig_n, _Func __f) {
8484
__identity __proj;
8585
return std::__for_each_n(__first, __orig_n, __f, __proj);
8686
}

libcxx/include/__algorithm/for_each_n_segment.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@
2323
_LIBCPP_BEGIN_NAMESPACE_STD
2424

2525
// __for_each_n_segment optimizes linear iteration over segmented iterators. It processes a segmented
26-
// input range defined by [__first, __first + __n), where __first is the starting segmented iterator
27-
// and __n is the number of elements to process. The functor __func is applied to each segment using
28-
// local iterator pairs for that segment. The return value of __func is ignored, and the function
29-
// returns an iterator pointing to one past the last processed element in the input range.
26+
// input range [__first, __first + __n) by applying the functor __func to each element within the segment.
27+
// The return value of __func is ignored, and the function returns an iterator pointing to one past the
28+
// last processed element in the input range.
3029

3130
template <class _SegmentedIterator, class _Size, class _Functor>
3231
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _SegmentedIterator

libcxx/include/__algorithm/ranges_for_each.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <__concepts/assignable.h>
1616
#include <__config>
1717
#include <__functional/identity.h>
18-
#include <__functional/invoke.h>
1918
#include <__iterator/concepts.h>
2019
#include <__iterator/projected.h>
2120
#include <__ranges/access.h>

libcxx/include/__algorithm/ranges_for_each_n.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <__algorithm/for_each_n.h>
1313
#include <__algorithm/in_fun_result.h>
1414
#include <__config>
15-
#include <__functional/identity.h>
16-
#include <__functional/invoke.h>
1715
#include <__iterator/concepts.h>
1816
#include <__iterator/incrementable_traits.h>
1917
#include <__iterator/iterator_traits.h>

0 commit comments

Comments
 (0)