[libcxx-commits] [libcxx] [libc++] Simplify most of the segmented iterator optimizations (PR #164797)
Louis Dionne via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Oct 23 08:15:28 PDT 2025
================
@@ -27,33 +28,28 @@ _LIBCPP_BEGIN_NAMESPACE_STD
template <class _ForwardIterator, class _Sentinel, class _Tp>
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
__fill(_ForwardIterator __first, _Sentinel __last, const _Tp& __value) {
+#ifndef _LIBCPP_CXX03_LANG
+ if constexpr (is_same<_ForwardIterator, _Sentinel>::value && __is_segmented_iterator_v<_ForwardIterator>) {
+ using __local_iterator_t = typename __segmented_iterator_traits<_ForwardIterator>::__local_iterator;
+ std::__for_each_segment(__first, __last, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) {
+ std::__fill(__lfirst, __llast, __value);
+ });
+ return __last;
+ }
+#endif
for (; __first != __last; ++__first)
*__first = __value;
return __first;
}
template <class _RandomAccessIterator,
class _Tp,
- __enable_if_t<__has_random_access_iterator_category<_RandomAccessIterator>::value &&
- !__is_segmented_iterator_v<_RandomAccessIterator>,
- int> = 0>
+ __enable_if_t<__has_random_access_iterator_category<_RandomAccessIterator>::value, int> = 0>
----------------
ldionne wrote:
```suggestion
__enable_if_t<__has_random_access_iterator_category<_RandomAccessIterator>::value && !__segmented_iterator<_RandomAccessIterator>::value, int> = 0>
```
This preserves previous "functionality" or at least code flow for segmented-and-random-access iterators. We can discuss removing that in a future patch, especially if we generalize `for_each_n_segment`.
https://github.com/llvm/llvm-project/pull/164797
More information about the libcxx-commits
mailing list