[libcxx-commits] [libcxx] [libc++] LWG4490: Allow calling `std::ranges::size` in ranges algorithms (PR #217460)
via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Aug 21 01:56:31 PDT 2026
eiytoq wrote:
> > > > In the general case, this patch does not affect performance. However, in the case identified by LWG4490, it can remove an O(n) traversal, thereby significantly improving the performance of algorithms such as `push_heap` in that case
> > >
> > >
> > > Then we should only modify `push_heap`, and not every algorithm in existence.
> >
> >
> > In this case, all of the algorithms this patch modified can remove a traversal, although the performance improvement varies between algorithms.
>
> How does `copy_backward` or `reverse_copy` remove a traversal? These algorithms go through the range exactly once, no matter the iterator kind.
They need to find the last iter
https://github.com/llvm/llvm-project/blob/50c5aa61e3c206191a2087b44a37f49f9f388327/libcxx/include/__algorithm/copy_backward.h#L164
https://github.com/llvm/llvm-project/blob/50c5aa61e3c206191a2087b44a37f49f9f388327/libcxx/include/__algorithm/ranges_reverse_copy.h#L54
In that case, they will lose the `sized_range` information and bring a redundant traversal.
https://github.com/llvm/llvm-project/pull/217460
More information about the libcxx-commits
mailing list