3765. const_sentinel should be constrained

Section: 25.2 [iterator.synopsis], [const.iterators.alias] Status: C++23 Submitter: Hewill Kang Opened: 2022-09-03 Last modified: 2023-11-22 15:47:43 UTC

Priority: Not Prioritized

View all other issues in [iterator.synopsis].

View all issues with C++23 status.


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
      // [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 [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.