Title
cartesian_product_view::iterator's default constructor is overconstrained
Status
new
Section
[ranges.cartesian.iterator]
Submitter
Hewill Kang

Created on 2023-01-06.00:00:00 last changed 3 weeks ago

Messages

Date: 2023-01-06.16:24:01

Proposed resolution:

This wording is relative to N4917.

  1. Modify [ranges.cartesian.iterator] as indicated:

    namespace std::ranges {
      template<input_range First, forward_range... Vs>
        requires (view<First> && ... && view<Vs>)
      template<bool Const>
      class cartesian_product_view<First, Vs...>::iterator {
      public:
        […]
        iterator() requires forward_range<maybe-const<Const, First>> = default;
        […]
      private:
        using Parent = maybe-const<Const, cartesian_product_view>;          // exposition only
        Parent* parent_ = nullptr;                                          // exposition only
        tuple<iterator_t<maybe-const<Const, First>>,
          iterator_t<maybe-const<Const, Vs>>...> current_;                  // exposition only
        […]
      };
    }
    
Date: 2023-01-06.00:00:00

Currently, cartesian_product_view::iterator only provides the default constructor when the first range models forward_range, which seems too restrictive since several input iterators like istream_iterator are still default-constructible.

It would be more appropriate to constrain the default constructor only by whether the underlying iterator satisfies default_initializable, as most other range adaptors do. Since cartesian_product_view::iterator contains a tuple member that already has a constrained default constructor, the proposed resolution simply removes the constraint.

History
Date User Action Args
2023-01-06 16:24:01adminsetmessages: + msg13185
2023-01-06 00:00:00admincreate