Skip to content

Commit 65f3b99

Browse files
committed
Added functor
1 parent 84a34c7 commit 65f3b99

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

libcxx/include/__algorithm/fill.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,21 @@ __fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& _
4343
std::fill_n(__first, __last - __first, __value);
4444
}
4545

46+
template <class _Tp>
47+
struct __fill_segment {
48+
const _Tp& __value_;
49+
50+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __fill_segment(const _Tp& __value) : __value_(__value) {}
51+
52+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR void operator()(_Tp& __val) const { __val = __value_; }
53+
};
54+
4655
template <class _SegmentedIterator,
4756
class _Tp,
4857
__enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0>
4958
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
5059
__fill(_SegmentedIterator __first, _SegmentedIterator __last, const _Tp& __value) {
51-
std::for_each(__first, __last, [__value](_Tp& __val) { __val = __value; });
60+
std::for_each(__first, __last, __fill_segment<_Tp>(__value));
5261
}
5362

5463
template <class _ForwardIterator, class _Tp>

libcxx/include/__algorithm/fill_n.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,22 @@ __fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
101101
return __first;
102102
}
103103

104+
template <class _Tp>
105+
struct __fill_n_segment {
106+
const _Tp& __value_;
107+
108+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR __fill_n_segment(const _Tp& __value) : __value_(__value) {}
109+
110+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR void operator()(_Tp& __val) const { __val = __value_; }
111+
};
112+
104113
template <class _OutputIterator,
105114
class _Size,
106115
class _Tp,
107116
__enable_if_t<__is_segmented_iterator<_OutputIterator>::value, int> >
108117
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _OutputIterator
109118
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) {
110-
std::for_each(__first, __first + __n, [__value](_Tp& __val) { __val = __value; });
119+
std::for_each(__first, __first + __n, __fill_n_segment<_Tp>(__value));
111120
return __n > 0 ? __first + __n : __first;
112121
}
113122

0 commit comments

Comments
 (0)