This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.

3492. Minimal improvements to elements_view::iterator

Section: 26.7.22.3 [range.elements.iterator] Status: WP Submitter: Michael Schellenberger Costa Opened: 2020-10-28 Last modified: 2021-02-26

Priority: 0

View all other issues in [range.elements.iterator].

View all issues with WP status.

Discussion:

During code review of elements_view for MSVC-STL we found two issues that should be easily addressed:

  1. elements_view::iterator constraints both operator++(int) member functions

    constexpr void operator++(int) requires (!forward_range<Base>);
    constexpr iterator operator++(int) requires forward_range<Base>;  
    

    However, given that a constrained method would be preferred we only need to constrain one of those. The proposal would be to remove the constraint from the void returning overload and change the declaration to

    constexpr void operator++(int);
    constexpr iterator operator++(int) requires forward_range<Base>;  
    
  2. elements_view::iterator operator- is constrained as follows:

    friend constexpr difference_type operator-(const iterator& x, const iterator& y)
      requires random_access_range<Base>; 
    

    However, that requires its base to have operator- defined. We should change the constraint to sized_sentinel_for<iterator_t<Base>, iterator_t<Base>>:

    friend constexpr difference_type operator-(const iterator& x, const iterator& y)
      requires sized_sentinel_for<iterator_t<Base>, iterator_t<Base>>;
    

[2020-11-01; Daniel comments]

Bullet (2) of the discussion has already been resolved by LWG 3483, it has therefore been omitted from the proposed wording below.

[2020-11-15; Reflector prioritization]

Set priority to 0 and status to Tentatively Ready after five votes in favour during reflector discussions.

[2021-02-26 Approved at February 2021 virtual plenary. Status changed: Tentatively Ready → WP.]

Proposed resolution:

This wording is relative to N4868.

This wording intentionally only touches operator++(int) and not operator-, see the 2020-11-01 comment for the reason why.

  1. Modify 26.7.22.3 [range.elements.iterator], class template elements_view::iterator synopsis, as indicated:

    […]
    constexpr iterator& operator++();
    constexpr void operator++(int) requires (!forward_range<Base>);
    constexpr iterator operator++(int) requires forward_range<Base>;
    […]
    
    […]
    constexpr void operator++(int) requires (!forward_range<Base>);
    

    -6- Effects: Equivalent to: ++current_.

    constexpr iterator operator++(int) requires forward_range<Base>;
    
    […]