Title
chunk_view::outer-iterator::value_type should provide reserve_hint
Status
wp
Section
[range.chunk.outer.value]
Submitter
Hewill Kang

Created on 2025-03-26.00:00:00 last changed 1 week ago

Messages

Date: 2025-06-23.16:37:24

Proposed resolution:

This wording is relative to N5008.

  1. 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_);
    
Date: 2025-06-23.16:37:24

[ Sofia 2025-06-21; Status changed: Voting → WP. ]

Date: 2025-06-15.00:00:00

[ 2025-06-12; Reflector poll ]

Set status to Tentatively Ready after five votes in favour during reflector poll.

Date: 2025-03-26.00:00:00

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-06-23 16:37:24adminsetmessages: + msg14861
2025-06-23 16:37:24adminsetstatus: voting -> wp
2025-06-12 20:59:27adminsetstatus: ready -> voting
2025-06-12 20:55:03adminsetmessages: + msg14802
2025-06-12 20:55:03adminsetstatus: new -> ready
2025-03-29 08:05:17adminsetmessages: + msg14710
2025-03-26 00:00:00admincreate