[libcxx-commits] [libcxx] [libc++] Optimize std::{, ranges}::{fill, fill_n} for segmented iterators (PR #132665)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 24 09:52:56 PDT 2025


================
@@ -26,9 +32,39 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 // fill_n isn't specialized for std::memset, because the compiler already optimizes the loop to a call to std::memset.
 
-template <class _OutputIterator, class _Size, class _Tp>
+template <class _OutputIterator,
+          class _Size,
+          class _Tp
+#ifndef _LIBCPP_CXX03_LANG
+          ,
+          __enable_if_t<_Or< _Not<__is_segmented_iterator<_OutputIterator> >,
+                             _Not<__has_random_access_local_iterator<_OutputIterator> > >::value,
+                        int> = 0
----------------
ldionne wrote:

I think it would be easier to follow if we reused exactly the same `enable_if` condition here and below. We could do this by using the following condition here:

```c++
__enable_if<!_And<__is_segmented_iterator<_OutputIterator>,
        __has_random_access_local_iterator<_OutputIterator> >::value>
```

And then just this below:

```c++
__enable_if<_And<__is_segmented_iterator<_OutputIterator>,
       __has_random_access_local_iterator<_OutputIterator> >::value>
```

This makes it clearer that one is the negation of the other.

https://github.com/llvm/llvm-project/pull/132665


More information about the libcxx-commits mailing list