This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++23 status.
move_iterator missingdisable_sized_sentinel_for specializationSection: 24.2[iterator.synopsis]Status:C++23Submitter: Hewill KangOpened: 2022-07-14Last modified: 2023-11-22
Priority:Not Prioritized
View all otherissues in [iterator.synopsis].
View all issues withC++23 status.
Discussion:
Sincereverse_iterator::operator- is not constrained, the standard adds adisable_sized_sentinel_for specialization for it to avoid situations where the underlying iterator can be subtracted makingreverse_iterator accidentally modelsized_sentinel_for.
move_iterator::operator- is also unconstrained and the standard does not have thedisable_sized_sentinel_for specialization for it, this makessubrange<move_iterator<I>, move_iterator<I>> unexpectedly satisfysized_range and incorrectly useI::operator- to get size whenI can be subtracted but not modeledsized_sentinel_for<I>.In addition, sinceP2520 makesmove_iterator no longer justinput_iterator,ranges::size can get the size of the range by subtracting twomove_iterator pairs,this also makesr | views::as_rvalue may satisfysized_range when neitherr norr | views::reverse issized_range.We should add amove_iterator version of thedisable_sized_sentinel_for specialization to the standard to avoid the above situation.[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 - bothmove_iterator andreverse_iterator'soperator- are constrained onx.base() - y.base()being valid."
Does anyone remember why we did this forreverse_iteratorand notmove_iterator?
[2022-11-12 Approved at November 2022 meeting in Kona. Status changed: Voting → WP.]
Proposed resolution:
This wording is relative toN4910.
Modify 24.2[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; […]}