ranges::const_iterator_t<range R> fails to accept arrays of unknown bound
Arthur O'Dwyer

Created on 2023-03-28.00:00:00 last changed 3 weeks ago


Date: 2023-11-07.22:39:32

Proposed resolution:

This wording is relative to N4944.

  1. Modify [ranges.syn] as indicated:

      template<class T>
        using iterator_t = decltype(ranges::begin(declval<T&&gt;()));    // freestanding
      template<range R>
        using sentinel_t = decltype(ranges::end(declval<R&&gt;()));      // freestanding
      template<rangeclass R>
        using const_iterator_t = const_iterator<iterator_t<R>>;       // freestanding
      template<range R>
        using const_sentinel_t = const_sentinel<sentinel_t<R>>;       // freestanding
Date: 2023-11-07.22:39:32

[ Kona 2023-11-07; Status changed: Open → NAD. ]

Date: 2023-11-07.22:39:32

[ Kona 2023-11-07; SG9 ]

SG9 considered this and noted it's obsolete due to LWG 3946. To support this case now would require changing ranges::cbegin to add a special case for arrays of unknown bound, which would require a paper.

Date: 2023-06-15.00:00:00

[ 2023-06-01; Reflector poll ]

Set priority to 3 after reflector poll. Several votes for NAD. Send to SG9 to be looked at with P2836.

Date: 2023-03-28.00:00:00

ranges::iterator_t<T> is unconstrained; but in contrast, ranges::const_iterator_t<T> constrains T to be a range, i.e., it must have an end.

    static_assert(std::is_same_v<std::ranges::iterator_t<int(&)[2]>, int*>);
    static_assert(std::is_same_v<std::ranges::iterator_t<int(&)[]>, int*>);  // OK
    static_assert(std::is_same_v<std::ranges::const_iterator_t<int(&)[2]>, const int*>);
    static_assert(std::is_same_v<std::ranges::const_iterator_t<int(&)[]>, const int*>);  // hard error

Date User Action Args
2023-11-07 22:39:32adminsetmessages: + msg13827
2023-11-07 22:39:32adminsetstatus: open -> nad
2023-11-07 21:10:51adminsetmessages: + msg13825
2023-06-01 14:35:38adminsetmessages: + msg13609
2023-06-01 14:35:38adminsetstatus: new -> open
2023-03-29 11:00:48adminsetmessages: + msg13502
2023-03-28 00:00:00admincreate