[PATCH 1/2] libstdc++: Introduce notion of segmented iterators

Yuao Ma addr2line@gmail.com
Wed Jul 15 12:16:57 GMT 2026


On Wed, Jul 15, 2026 at 3:02 PM Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On Tue, 14 Jul 2026, 15:56 Tomasz Kaminski, <tkaminsk@redhat.com> wrote:
>>
>>>
>>>
>>> fold_right{, _last} could use backward iteration, but it can also be
>>> implemented with reverse iterators.
>>
>> Is there a big benefit from iterating over segments, versus the whole range
>> for fold? And other algorithms that visit all elements. I was thinking mostly
>> about cases like distance (where we can compare iterators), or copy
>> (when we could `memcpy` the segment).
>
> 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.
>

Based on my experience with libc++, I believe at least some algorithms
would benefit from segmented iterators.

ref: https://github.com/llvm/llvm-project/issues/102817

>
>>>


More information about the Libstdc++ mailing list