Title
view_interface::cbegin is underconstrained
Status
c++23
Section
[view.interface.general]
Submitter
Hewill Kang

Created on 2022-09-04.00:00:00 last changed 13 months ago

Messages

Date: 2022-11-17.00:42:33

Proposed resolution:

This wording is relative to n4917.

  1. Modify [view.interface.general] as indicated:

    namespace std::ranges {
      template<class D>
        requires is_class_v<D> && same_as<D, remove_cv_t<D>>
      class view_interface {
        […]
      public:
        […]
        constexpr auto cbegin() requires input_range<D> {
          return ranges::cbegin(derived());
        }
        constexpr auto cbegin() const requires input_range<const D> {
          return ranges::cbegin(derived());
        }
        constexpr auto cend() requires input_range<D> {
          return ranges::cend(derived());
        }
        constexpr auto cend() const requires input_range<const D> {
          return ranges::cend(derived());
        }
        […]
      };
    }
    
Date: 2022-11-12.00:00:00

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

Date: 2022-11-11.02:39:56

[ Kona 2022-11-08; Accepted at joint LWG/SG9 session. Move to Immediate ]

Date: 2022-09-15.00:00:00

[ 2022-09-25; Hewill provides improved wording ]

Date: 2022-09-15.00:00:00

[ 2022-09-23; Reflector poll ]

Set priority to 2 after reflector poll.

This should be done for cend too.

Previous resolution [SUPERSEDED]:

This wording is relative to n4917.

  1. Modify [view.interface.general] as indicated:

    namespace std::ranges {
      template<class D>
        requires is_class_v<D> && same_as<D, remove_cv_t<D>>
      class view_interface {
        […]
      public:
        […]
        constexpr auto cbegin() requires input_range<D> {
          return ranges::cbegin(derived());
        }
        constexpr auto cbegin() const requires input_range<const D> {
          return ranges::cbegin(derived());
        }
        […]
      };
    }
    
Date: 2022-09-04.00:00:00

Currently, view_interface::cbegin simply returns ranges::cbegin(derived()), which returns the type alias const_iterator for its iterator, which requires that the template parameter I must model the input_iterator.

Given that view_interface::cbegin does not have any constraints, when D models only output_range, calling its cbegin() will result in a hard error inside the function body:

#include <ranges>
#include <vector>

int main() {
  std::vector<int> v;
  auto r = std::views::counted(std::back_inserter(v), 3);
  auto b = r.cbegin(); // hard error
}

We should add a constraint for view_interface::cbegin that D must model input_range.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-11-17 00:42:33adminsetmessages: + msg13092
2022-11-17 00:42:33adminsetstatus: immediate -> wp
2022-11-11 02:39:56adminsetstatus: ready -> immediate
2022-11-10 23:33:20adminsetmessages: + msg13004
2022-11-10 23:33:20adminsetstatus: new -> ready
2022-09-25 06:36:20adminsetmessages: + msg12808
2022-09-23 15:44:07adminsetmessages: + msg12800
2022-09-06 15:53:57adminsetmessages: + msg12742
2022-09-04 00:00:00admincreate