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

3768. possibly-const-range is overconstrained

Section: 25.2 [ranges.syn] Status: NAD Submitter: Hewill Kang Opened: 2022-09-08 Last modified: 2022-11-30

Priority: Not Prioritized

View other active issues in [ranges.syn].

View all other issues in [ranges.syn].

View all issues with NAD status.

Discussion:

Due to the possibly-const-range constraint that the template parameter R must model input_range, this makes the ranges::cend that tries using it for meaningful const casting never be applied to an output_range, even though const_sentinel does not require the template parameter S to model input_iterator.

This is unnecessary, we should relax its constraint.

[2022-09-23; Reflector poll]

Tentatively NAD. "const output ranges don’t seem to be useful."

[2022-11-30 LWG telecon. Status changed: Tentatively NAD → NAD.]

Proposed resolution:

This wording is relative to N4917.

  1. Modify 25.2 [ranges.syn] as indicated:

    #include <compare>              // see 17.11.1 [compare.syn]
    #include <initializer_list>     // see 17.10.2 [initializer.list.syn]
    #include <iterator>             // see 24.2 [iterator.synopsis]
    
    namespace std::ranges {
      […]
    
      // 25.7.22 [range.as.const], as const view
      template<input_range R>
        constexpr auto& possibly-const-range(R& r) {          // exposition only
          if constexpr (constant_range<const R> && !constant_range<R>) {
            return const_cast<const R&>(r);
          } else {
            return r;
          }
        } 
      
      […]
    }