Title
adjacent_view, adjacent_transform_view and slide_view missing base accessor
Status
new
Section
[range.adjacent.view] [range.adjacent.transform.view] [range.slide.view]
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 [range.adjacent.view] as indicated:

    namespace std::ranges {
      template<forward_range V, size_t N>
        requires view<V> && (N > 0)
      class adjacent_view : public view_interface<adjacent_view<V, N>> {
        V base_ = V();                      // exposition only
        […]
      public:
        adjacent_view() requires default_initializable<V> = default;
        constexpr explicit adjacent_view(V base);
    
        constexpr V base() const & requires copy_constructible<V> { return base_; }
        constexpr V base() && { return std::move(base_); }
        […]
      };
    }
    
  2. Modify [range.adjacent.transform.view] as indicated:

    namespace std::ranges {
      template<forward_range V, move_constructible F, size_t N>
        requires view<V> && (N > 0) && is_object_v<F> &&
                 regular_invocable<F&, REPEAT(range_reference_t<V>, N)...> &&
                 can-reference<invoke_result_t<F&, REPEAT(range_reference_t<V>, N)...>>
      class adjacent_transform_view : public view_interface<adjacent_transform_view<V, F, N>> {
        movable-box<F> fun_;                        // exposition only
        adjacent_view<V, N> inner_;                 // exposition only
    
        using InnerView = adjacent_view<V, N>;      // exposition only
        […]
      public:
        adjacent_transform_view() = default;
        constexpr explicit adjacent_transform_view(V base, F fun);
    
        constexpr V base() const & requires copy_constructible<InnerView> { return inner_.base(); }
        constexpr V base() && { return std::move(inner_).base(); }
        […]
      };
    }
    
  3. Modify [range.slide.view] as indicated:

    namespace std::ranges {
      […]
      template<forward_range V>
        requires view<V>
      class slide_view : public view_interface<slide_view<V>> {
        V base_;                            // exposition only
        range_difference_t<V> n_;           // exposition only
        […]
      public:
        constexpr explicit slide_view(V base, range_difference_t<V> n);
    
        constexpr V base() const & requires copy_constructible<V> { return base_; }
        constexpr V base() && { return std::move(base_); }
        […]
      };
      […]
    }
    
Date: 2023-01-06.00:00:00

Like most range adaptors, these three views accept a single range and store it as a member variable. However, they do not provide a base() member function for accessing the underlying range, which seems like an oversight.

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