Skip to content

[ranges] Should constexpr default_sentinel_t end() be const-qualified? #5507

@hewillk

Description

@hewillk

The begin/end of basic_istream_view is defined in [range.istream.view]

template<movable Val, class CharT, class Traits = char_traits<CharT>>
class basic_istream_view : public view_interface<basic_istream_view<Val, CharT, Traits>> {
public:
  constexpr auto begin() {
    *stream_ >> value_;
    return iterator{*this};
  }
  constexpr default_sentinel_t end() const noexcept;
};

Even if begin() is non-const-qualified, since end() simply returns default_sentinel, it is still designed to be const-qualified member function, which allows us to call as_const(r).end() even if as_const(r) is not a range.

However, the begin/end of chunk_view for input ranges is defined in [range.chunk.view.input] as

template<view V>
class chunk_view : public view_interface<chunk_view<V>> {
public:
  constexpr outer-iterator begin();
  constexpr default_sentinel_t end() noexcept;
};

Even though end() can be const-qualified, it is still designed to be non-const-qualified, which makes end()'s const-qualification consistent with begin()'s and prevents us from calling as_const(r).end().

Do we need to resolve this inconsistency?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions