Why does view_interface::data const overload need an extra check that const D satisfies ranges::range?

Viewed 108

According to [view.interface], non-const and const overloaded data functions are defined as follows:

template<class D>
  requires is_class_v<D> && same_­as<D, remove_cv_t<D>>
class view_interface : public view_base {
private:
  constexpr D& derived() noexcept {                   // exposition only
    return static_cast<D&>(*this);
  }
  constexpr const D& derived() const noexcept {       // exposition only
    return static_cast<const D&>(*this);
  }
public:
  constexpr auto data() requires contiguous_­iterator<iterator_t<D>> {
    return to_address(ranges::begin(derived()));
  }
  constexpr auto data() const
    requires range<const D> && contiguous_­iterator<iterator_t<const D>> {
      return to_address(ranges::begin(derived()));
    }
};

Why does data() const need to additionally satisfy that const D is a ranges::range? Isn't iterator_t<const D> already restricted so that const D must be a ranges::range?

What is the real purpose of requires range<const D> here? Is there a situation where D is a ranges::range and const D is not a ranges::range?

0 Answers
Related