Title
lazy_split_view should be sized_range when pattern is empty tiny-range
Status
open
Section
[range.lazy.split.view][range.split.view]
Submitter
Hewill Kang

Created on 2024-05-23.00:00:00 last changed 4 months ago

Messages

Date: 2024-08-02.21:52:03

Proposed resolution:

This wording is relative to N4981.

  1. Modify [range.lazy.split.view] as indicated:

    namespace std::ranges {
      template<auto> struct require-constant;                        // exposition only
    
      template<class R>
      concept tiny-range =                                           // exposition only
         sized_range<R> &&
         requires { typename require-constant<remove_reference_t<R>::size()>; } &&
         (remove_reference_t<R>::size() <= 1);
      
      template<input_range V, forward_range Pattern>
        requires view<V> && view<Pattern> &&
                 indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to> &&
                 (forward_range<V> || tiny-range<Pattern>)
      class lazy_split_view : public view_interface<lazy_split_view<V, Pattern>> {
        […]
        constexpr auto size()
          requires sized_range<V> &&
                   tiny-range<Pattern> && (Pattern::size() == 0) {
          return ranges::size(base_);
        }
    
        constexpr auto size() const
          requires sized_range<const V> &&
                   tiny-range<Pattern> && (Pattern::size() == 0) {
          return ranges::size(base_);
        }
      };
      […]
    }
    
  2. Modify [range.split.view] as indicated:

    namespace std::ranges {
      template<forward_range V, forward_range Pattern>
        requires view<V> && view<Pattern> &&
                 indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to>
      class split_view : public view_interface<split_view<V, Pattern>> {
        […]
        constexpr auto size()
          requires sized_range<V> &&
                   tiny-range<Pattern> && (Pattern::size() == 0) {
          return ranges::size(base_);
        }
    
        constexpr auto size() const
          requires sized_range<const V> &&
                   tiny-range<Pattern> && (Pattern::size() == 0) {
          return ranges::size(base_);
        }
      };
      […]
    }
    
Date: 2024-08-15.00:00:00

[ 2024-08-02; Reflector poll ]

Set priority to 4 after reflector poll. Set Status to SG9. "Design change". "tiny-range should accept span<T, 0|1> or ref_view<array<T, 0|1>>, see related paper p1419."

Date: 2024-05-23.00:00:00

When the pattern range is empty, lazy_split_view will split each element into individual subranges, which means its size is equal to the size of the underlying range.

Since we already have a tiny-range that can determine whether the range is empty by its type, it seems valuable to provide a size for lazy_split_view in this case, given that we already specifically checked for it by Pattern::size() == 0 in inner-iterator::operator++().

History
Date User Action Args
2024-08-02 21:52:03adminsetmessages: + msg14291
2024-08-02 21:52:03adminsetstatus: new -> open
2024-05-26 07:51:59adminsetmessages: + msg14158
2024-05-23 00:00:00admincreate