https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123211
Bug ID: 123211
Summary: Consider specializing ranges::distance for join_view
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
Barry pointed out that calling ranges::distance on a join_view will count every
element one by one (because its iterator concept is never stronger than
bidirectional), but when joining sized ranges it would be better to loop over
the underlying views and call ranges::distance on each of them.
Something like:
if constexpr (is-specialization-of<R, join_view>)
return ranges::accumulate(r.base(), range_difference_t<R>(0),
std::plus<>{}, ranges::distance);
(except not that, because we don't have ranges::accumulate yet).
https://old.reddit.com/r/cpp/comments/1pptoq2/stdranges_may_not_deliver_the_performance_that/nupp6nm/