2121# pragma GCC system_header
2222#endif
2323
24- _LIBCPP_PUSH_MACROS
25- #include < __undef_macros>
26-
2724_LIBCPP_BEGIN_NAMESPACE_STD
2825
2926template <class _InputIterator , class _Sent , class _Func >
@@ -32,29 +29,19 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __for_each(_InputIterat
3229 __f (*__first);
3330}
3431
35- // __segment_processor handles the per-segment processing by applying the function object __func_ to each
36- // element within the segment.
37- template <class _Func >
38- struct __segment_processor {
39- _Func& __func_;
40-
41- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __segment_processor (_Func& __f) : __func_(__f) {}
42-
43- template <class _SegmentedIterator >
44- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
45- operator ()(typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator __lfirst,
46- typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator __llast) {
47- std::__for_each (__lfirst, __llast, __func_);
48- }
49- };
50-
32+ #ifndef _LIBCPP_CXX03_LANG
5133template <class _SegmentedIterator ,
5234 class _Function ,
5335 __enable_if_t <__is_segmented_iterator<_SegmentedIterator>::value, int > = 0 >
5436_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
5537__for_each (_SegmentedIterator __first, _SegmentedIterator __last, _Function& __func) {
56- std::__for_each_segment (__first, __last, std::__segment_processor<_Function>(__func));
38+ using _Traits = __segmented_iterator_traits<_SegmentedIterator>;
39+ std::__for_each_segment (
40+ __first, __last, [&](typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
41+ std::__for_each (__lfirst, __llast, __func);
42+ });
5743}
44+ #endif
5845
5946template <class _InputIterator , class _Function >
6047_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function
@@ -65,6 +52,4 @@ for_each(_InputIterator __first, _InputIterator __last, _Function __f) {
6552
6653_LIBCPP_END_NAMESPACE_STD
6754
68- _LIBCPP_POP_MACROS
69-
7055#endif // _LIBCPP___ALGORITHM_FOR_EACH_H
0 commit comments