Title
move_iterator missing disable_sized_sentinel_for specialization
Status
c++23
Section
[iterator.synopsis]
Submitter
Hewill Kang

Created on 2022-07-14.00:00:00 last changed 4 months ago

Messages

Date: 2022-11-17.00:42:33

Proposed resolution:

This wording is relative to N4910.

  1. Modify [iterator.synopsis], header <iterator> synopsis, as indicated:

    namespace std::ranges {
      […]
      template<class Iterator>
        constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
    
      template<class Iterator1, class Iterator2>
          requires (!sized_sentinel_for<Iterator1, Iterator2>)
        inline constexpr bool disable_sized_sentinel_for<move_iterator<Iterator1>,
                                                         move_iterator<Iterator2>> = true;
    
      […]
    }
    
Date: 2022-11-12.00:00:00

[ 2022-11-12 Approved at November 2022 meeting in Kona. Status changed: Voting → WP. ]

Date: 2022-08-15.00:00:00

[ 2022-08-23; Reflector poll ]

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

"but I don't think the issue text is quite right - both move_iterator and reverse_iterator's operator- are constrained on x.base() - y.base() being valid."

Does anyone remember why we did this for reverse_iterator and not move_iterator?

Date: 2022-07-14.00:00:00

Since reverse_iterator::operator- is not constrained, the standard adds a disable_sized_sentinel_for specialization for it to avoid situations where the underlying iterator can be subtracted making reverse_iterator accidentally model sized_sentinel_for.

However, given that move_iterator::operator- is also unconstrained and the standard does not have the disable_sized_sentinel_for specialization for it, this makes subrange<move_iterator<I>, move_iterator<I>> unexpectedly satisfy sized_range and incorrectly use I::operator- to get size when I can be subtracted but not modeled sized_sentinel_for<I>.

In addition, since P2520 makes move_iterator no longer just input_iterator, ranges::size can get the size of the range by subtracting two move_iterator pairs, this also makes r | views::as_rvalue may satisfy sized_range when neither r nor r | views::reverse is sized_range.

We should add a move_iterator version of the disable_sized_sentinel_for specialization to the standard to avoid the above situation.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-11-17 00:42:33adminsetmessages: + msg13055
2022-11-17 00:42:33adminsetstatus: voting -> wp
2022-11-08 03:46:49adminsetstatus: ready -> voting
2022-08-23 15:24:34adminsetmessages: + msg12689
2022-08-23 15:24:34adminsetstatus: new -> ready
2022-07-16 12:31:13adminsetmessages: + msg12586
2022-07-14 00:00:00admincreate