21 Containers library [containers]

21.7 Views [views]

21.7.3 Class template span [views.span]

21.7.3.2 Constructors, copy, and assignment [span.cons]

constexpr span() noexcept;
Ensures: size() == 0 && data() == nullptr.
Remarks: This constructor shall not participate in overload resolution unless Extent <= 0 is true.
constexpr span(pointer ptr, index_type count);
Requires: [ptr, ptr + count) shall be a valid range.
If extent is not equal to dynamic_­extent, then count shall be equal to extent.
Effects: Constructs a span that is a view over the range [ptr, ptr + count).
Ensures: size() == count && data() == ptr.
Throws: Nothing.
constexpr span(pointer first, pointer last);
Requires: [first, last) shall be a valid range.
If extent is not equal to dynamic_­extent, then last - first shall be equal to extent.
Effects: Constructs a span that is a view over the range [first, last).
Ensures: size() == last - first && data() == first.
Throws: Nothing.
template<size_t N> constexpr span(element_type (&arr)[N]) noexcept; template<size_t N> constexpr span(array<value_type, N>& arr) noexcept; template<size_t N> constexpr span(const array<value_type, N>& arr) noexcept;
Effects: Constructs a span that is a view over the supplied array.
Ensures: size() == N && data() == data(arr).
Remarks: These constructors shall not participate in overload resolution unless:
  • extent == dynamic_­extent || N == extent is true, and
  • remove_­pointer_­t<decltype(data(arr))>(*)[] is convertible to ElementType(*)[].
template<class Container> constexpr span(Container& cont); template<class Container> constexpr span(const Container& cont);
Requires: [data(cont), data(cont) + size(cont)) shall be a valid range.
If extent is not equal to dynamic_­extent, then size(cont) shall be equal to extent.
Effects: Constructs a span that is a view over the range [data(cont), data(cont) + size(cont)).
Ensures: size() == size(cont) && data() == data(cont).
Throws: What and when data(cont) and size(cont) throw.
Remarks: These constructors shall not participate in overload resolution unless:
  • Container is not a specialization of span,
  • Container is not a specialization of array,
  • is_­array_­v<Container> is false,
  • data(cont) and size(cont) are both well-formed, and
  • remove_­pointer_­t<decltype(data(cont))>(*)[] is convertible to ElementType(*)[].
constexpr span(const span& other) noexcept = default;
Ensures: other.size() == size() && other.data() == data().
template<class OtherElementType, ptrdiff_t OtherExtent> constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;
Effects: Constructs a span that is a view over the range [s.data(), s.data() + s.size()).
Ensures: size() == s.size() && data() == s.data().
Remarks: This constructor shall not participate in overload resolution unless:
  • Extent == dynamic_­extent || Extent == OtherExtent is true, and
  • OtherElementType(*)[] is convertible to ElementType(*)[].
constexpr span& operator=(const span& other) noexcept = default;
Ensures: size() == other.size() && data() == other.data().