This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.
view_interface::operator[]Section: 25.5.3 [view.interface] Status: New Submitter: Hewill Kang Opened: 2026-05-11 Last modified: 2026-05-16
Priority: Not Prioritized
View other active issues in [view.interface].
View all other issues in [view.interface].
View all issues with New status.
Discussion:
Hardening view_interface::operator[] to prevent out-of-bounds access is worthwhile for the
sized_range cases, and we have already done so for other standard views such as span
and string_view's operator[].
Proposed resolution:
This wording is relative to N5046.
Modify 25.5.3 [view.interface], class template view_interface synopsis, as indicated:
namespace std::ranges {
template<class D>
requires is_class_v<D> && same_as<D, remove_cv_t<D>>
class view_interface {
[…]
public:
[…]
template<random_access_range R = D>
constexpr decltype(auto) operator[](range_difference_t<R> n) {
return ranges::begin(derived())[n];
};
template<random_access_range R = const D>
constexpr decltype(auto) operator[](range_difference_t<R> n) const {
return ranges::begin(derived())[n];
};
};
}
Modify 25.5.3.2 [view.interface.members] as indicated:
constexpr decltype(auto) back() requires bidirectional_range<D> && common_range<D>; constexpr decltype(auto) back() const requires bidirectional_range<const D> && common_range<const D>;-3- Hardened preconditions:
-4- Effects: Equivalent to:!empty()istrue.return *ranges::prev(ranges::end(derived()));template<random_access_range R = D> constexpr decltype(auto) operator[](range_difference_t<R> n); template<random_access_range R = const D> constexpr decltype(auto) operator[](range_difference_t<R> n) const;-?- Hardened preconditions: If
-?- Effects: Equivalent to:Dmodelssized_range, thenn >= 0 && n < ranges::distance(derived())istrue.return ranges::begin(derived())[n];