Title
subrange should prevent slicing for contiguous iterators
Status
new
Section
[range.subrange.general]
Submitter
Hewill Kang

Created on 2026-04-03.00:00:00 last changed 2 weeks ago

Messages

Date: 2026-04-04.15:38:16

Proposed resolution:

This wording is relative to N5032.

  1. Modify [range.subrange.general] as indicated:

    namespace std::ranges {
      template<class From, class To>
        concept uses-nonqualification-pointer-conversion =      // exposition only
          is_pointer_vcontiguous_iterator<From> && is_pointer_vcontiguous_iterator<To> &&
          !convertible_to<remove_pointer_tremove_reference_t<iter_reference_t<From>>(*)[], 
                          remove_pointer_tremove_reference_t<iter_reference_t<To>>(*)[]>;
       […]
    }
    
Date: 2026-04-03.00:00:00

Currently, the subrange uses the following exposition-only concept:

template<class From, class To>
  concept uses-nonqualification-pointer-conversion =      // exposition only
    is_pointer_v<From> && is_pointer_v<To> &&
    !convertible_to<remove_pointer_t<From>(*)[], remove_pointer_t<To>(*)[]>;

to disallow derived to base conversions. However, this only applies to pointers.

Given that subrange is intended to universally take any iterator-pair to form a view, we may need to generally prevent this in the case of contiguous iterators (demo):

struct Base {};
struct Derived : Base {};
ranges::subrange<Derived*> sd;
ranges::subrange<Base*> sb = sd;                        // error
ranges::subrange<const Base*> sb = views::as_const(sd); // ok
History
Date User Action Args
2026-04-04 15:38:16adminsetmessages: + msg16254
2026-04-03 00:00:00admincreate