<div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jul 15, 2026 at 2:17 PM Yuao Ma <<a href="mailto:addr2line@gmail.com" target="_blank">addr2line@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Jul 15, 2026 at 3:02 PM Jonathan Wakely <<a href="mailto:jwakely.gcc@gmail.com" target="_blank">jwakely.gcc@gmail.com</a>> wrote:<br>
> On Tue, 14 Jul 2026, 15:56 Tomasz Kaminski, <<a href="mailto:tkaminsk@redhat.com" target="_blank">tkaminsk@redhat.com</a>> wrote:<br>
>><br>
>>><br>
>>><br>
>>> fold_right{, _last} could use backward iteration, but it can also be<br>
>>> implemented with reverse iterators.<br>
>><br>
>> Is there a big benefit from iterating over segments, versus the whole range<br>
>> for fold? And other algorithms that visit all elements. I was thinking mostly<br>
>> about cases like distance (where we can compare iterators), or copy<br>
>> (when we could `memcpy` the segment).<br>
><br>
> Right, there are certainly algorithms that iterate backwards (copy_backward for an obvious example!) but I don't think they benefit from having contiguous or random access iterators, rather than just bidirectional. So I don't think optimising for segments matters.<br>
><br>
<br>
Based on my experience with libc++, I believe at least some algorithms<br>
would benefit from segmented iterators.<br>
<br>
ref: <a href="https://github.com/llvm/llvm-project/issues/102817" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/issues/102817</a></blockquote><div>Would algorithms like fill/fold/transform benefit from for_each primitive?<br></div><div>I.e. something that iterates over all elements and invokes the provided callback.<br></div><div>Because such operation can be implemented with a lot less code for views like</div><div>filter/transform or also join. </div><div><br></div><div>I see the value of segmented iterator, in situations where the algorithm can</div><div>process some kind of ranges: sized for distance or contiguous for memcopy</div><div>in a more efficient manner (in bulk) rather than element wise. <br><br></div><div>Or the changes work in tandem with other optimizations? Like using an</div><div>SIMD implementation of fold, when applying it on the segment?<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
<br>
><br>
>>><br>
<br>
</blockquote></div></div>
</div>