Title
common_view::end should improve random_access_range case
Status
c++23
Section
[range.common.view]
Submitter
Hewill Kang

Created on 2022-06-15.00:00:00 last changed 12 months ago

Messages

Date: 2022-11-17.00:42:33

Proposed resolution:

This wording is relative to N4917.

  1. Modify [range.common.view] as indicated:

    namespace std::ranges {
      template<view V>
        requires (!common_range<V> && copyable<iterator_t<V>>)
      class common_view : public view_interface<common_view<V>> {
      private:
        V base_ = V();  // exposition only
      public:
        […]
        constexpr auto begin() {
          if constexpr (random_access_range<V> && sized_range<V>)
            return ranges::begin(base_);
          else
            return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::begin(base_));
        }
    
        constexpr auto begin() const requires range<const V> {
          if constexpr (random_access_range<const V> && sized_range<const V>)
            return ranges::begin(base_);
          else
            return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::begin(base_));
        }
        
        constexpr auto end() {
          if constexpr (random_access_range<V> && sized_range<V>)
            return ranges::begin(base_) + ranges::sizedistance(base_);
          else
            return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::end(base_));
        }
    
        constexpr auto end() const requires range<const V> {
          if constexpr (random_access_range<const V> && sized_range<const V>)
            return ranges::begin(base_) + ranges::sizedistance(base_);
          else
            return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::end(base_));
        }
    
        constexpr auto size() requires sized_range<V> {
          return ranges::size(base_);
        }
        constexpr auto size() const requires sized_range<const V> {
          return ranges::size(base_);
        }
      };
      […]
    }
    
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.21:08:08

[ Kona 2022-11-10; Move to Immediate ]

Date: 2022-11-09.00:00:00

[ 2022-11-09 Tim updates wording per LWG discussion ]

Date: 2022-11-10.23:33:20

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

Date: 2022-07-15.00:00:00

[ 2022-07-06; Reflector poll ]

Set priority to 3 after reflector poll.

Previous resolution [SUPERSEDED]:

This wording is relative to N4910.

  1. Modify [range.common.view] as indicated:

    namespace std::ranges {
      template<view V>
        requires (!common_range<V> && copyable<iterator_t<V>>)
      class common_view : public view_interface<common_view<V>> {
      private:
        V base_ = V();  // exposition only
      public:
        […]
        constexpr auto begin() {
          if constexpr (random_access_range<V> && sized_range<V>)
            return ranges::begin(base_);
          else
            return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::begin(base_));
        }
    
        constexpr auto begin() const requires range<const V> {
          if constexpr (random_access_range<const V> && sized_range<const V>)
            return ranges::begin(base_);
          else
            return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::begin(base_));
        }
        
        constexpr auto end() {
          if constexpr (random_access_range<V> && sized_range<V>)
            return ranges::begin(base_) + range_difference_t<V>(size())ranges::size(base_);
          else
            return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::end(base_));
        }
    
        constexpr auto end() const requires range<const V> {
          if constexpr (random_access_range<const V> && sized_range<const V>)
            return ranges::begin(base_) + range_difference_t<const V>(size())ranges::size(base_);
          else
            return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::end(base_));
        }
    
        constexpr auto size() requires sized_range<V> {
          return ranges::size(base_);
        }
        constexpr auto size() const requires sized_range<const V> {
          return ranges::size(base_);
        }
      };
      […]
    }
    
Date: 2022-11-11.21:08:08

This issue is part of NB comment US 47-109 26 [ranges] Resolve open issues

In view of the fact that random access iterators are only required to work with its difference type, P2393R1 improves the wording of take_view, which first convert the integer type to difference type and then operate with the iterator. However, the paper omits the handling of random access iterators in common_view::end, which directly operates on the return types of ranges::begin and ranges::size. We should improve this, too.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-11-17 00:42:33adminsetmessages: + msg13089
2022-11-17 00:42:33adminsetstatus: immediate -> wp
2022-11-11 21:08:08adminsetmessages: + msg13024
2022-11-11 21:08:08adminsetstatus: open -> immediate
2022-11-10 23:33:20adminsetmessages: + msg13002
2022-11-10 23:33:20adminsetstatus: new -> open
2022-11-09 22:36:20adminsetmessages: + msg12980
2022-07-06 16:27:07adminsetmessages: + msg12552
2022-06-15 18:16:27adminsetmessages: + msg12505
2022-06-15 00:00:00admincreate