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.

3765. const_sentinel should be constrained

Section: 25.2 [iterator.synopsis], 25.5.3.2 [const.iterators.alias] Status: WP Submitter: Hewill Kang Opened: 2022-09-03 Last modified: 2022-11-17

Priority: Not Prioritized

View all other issues in [iterator.synopsis].

View all issues with WP status.

Discussion:

The current standard does not have any constraints on const_sentinel template parameters, which makes it possible to pass almost any type of object to make_const_sentinel. It would be more appropriate to constrain the type to meet the minimum requirements of the sentinel type such as semiregular as move_sentinel does.

[2022-09-23; Reflector poll]

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

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

Proposed resolution:

This wording is relative to N4917.

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

    #include <compare>              // see 17.11.1 [compare.syn]
    #include <concepts>             // see 18.3 [concepts.syn]
    
    namespace std {
      […]
      
      // 25.5.3 [const.iterators], constant iterators and sentinels
      // 25.5.3.2 [const.iterators.alias], alias templates
      […]
      template<input_iterator I>
        using const_iterator = see below;                                               // freestanding
      template<semiregularclass S>
        using const_sentinel = see below;                                               // freestanding
    
      […]
      template<input_iterator I>
        constexpr const_iterator<I> make_const_iterator(I it) { return it; }            // freestanding
    
      template<semiregularclass S>
        constexpr const_sentinel<S> make_const_sentinel(S s) { return s; }              // freestanding
      […]
    }
    
  2. Modify 25.5.3.2 [const.iterators.alias] as indicated:

    template<semiregularclass S>
      using const_sentinel = see below;
    

    -2- Result: If S models input_iterator, const_iterator<S>. Otherwise, S.