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

3849. cartesian_product_view::iterator's default constructor is overconstrained

Section: 26.7.33.3 [range.cartesian.iterator] Status: C++23 Submitter: Hewill Kang Opened: 2023-01-06 Last modified: 2023-11-22

Priority: Not Prioritized

View all other issues in [range.cartesian.iterator].

View all issues with C++23 status.

Discussion:

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.

[2023-02-01; Reflector poll]

Set status to Tentatively Ready after nine votes in favour during reflector poll.

[2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting → WP.]

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
        […]
      };
    }