Created on 2025-03-26.00:00:00 last changed 6 days ago
Proposed resolution:
This wording is relative to N5008.
Modify [range.chunk.outer.value] as indicated:
[…]namespace std::ranges { template<view V> requires input_range<V> struct chunk_view<V>::outer-iterator::value_type : view_interface<value_type> { […] constexpr auto size() const requires sized_sentinel_for<sentinel_t<V>, iterator_t<V>>; constexpr auto reserve_hint() const noexcept; }; }constexpr auto size() const requires sized_sentinel_for<sentinel_t<V>, iterator_t<V>>;-4- Effects: Equivalent to:
return to-unsigned-like(ranges::min(parent_->remainder_, ranges::end(parent_->base_) - *parent_->current_));constexpr auto reserve_hint() const noexcept;-?- Effects: Equivalent to:
return to-unsigned-like(parent_->remainder_);
Consider:
views::istream<int>(is) | views::chunk(N) | ranges::to<std::list<std::vector<int>>>();
When the stream is large enough, each chunk will be of size N in most cases, except it is the last chunk.
In this case, there is no reason not to provide a reserve_hint
as this can be easily done by just
return remainder_
. Otherwise, when N is large, each vector will be reallocated
multiple times unnecessarily.
This is also consistent with the forward_range
version, since its value type is
views::take(subrange(current_, end_), n_)
, which always has a
reserve_hint
as take_view
unconditionally provides it.
History | |||
---|---|---|---|
Date | User | Action | Args |
2025-03-29 08:05:17 | admin | set | messages: + msg14710 |
2025-03-26 00:00:00 | admin | create |