3

Is std::span a view?

My speculation stems from the fact that it does not "own".

I have read that it is a reference to ranges here and that it "just wraps" I have not seen anywhere been stated explicitly that it is a view.

gonidelis
  • 885
  • 10
  • 32
  • 2
    It probably can be considered as a view since it's just a *pointer* + a *size*. Although it allows you to modify the source. So it's not exactly similar to e.g. `string_view`. – digito_evo Jan 13 '22 at 20:59
  • 1
    I am not an expert in this terminology, but it has been shared in respectable circles that "a view can not modify". For some definition of "view". – Drew Dormann Jan 13 '22 at 21:06
  • @DrewDormannD [What is a `view`?](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2415r2.html) – 康桓瑋 Jan 14 '22 at 04:00

1 Answers1

4

Generally span is a reference-like class type.

As for "view": is this related to what you're asking? (source)

template<class T, std::size_t Extent> inline constexpr bool
ranges::enable_view<std::span<T, Extent>> = true; 

This specialization of ranges::enable_view makes span satisfy view.

alagner
  • 3,448
  • 1
  • 13
  • 25