22 Containers library [containers]

22.7 Views [views]

22.7.3 Class template span [views.span]

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

constexpr span() noexcept;
Constraints: Extent == dynamic_­extent || Extent == 0 is true.
Postconditions: size() == 0 && data() == nullptr.
constexpr span(pointer ptr, index_type count);
Preconditions: [ptr, ptr + count) is a valid range.
If extent is not equal to dynamic_­extent, then count is equal to extent.
Effects: Constructs a span that is a view over the range [ptr, ptr + count).
Postconditions: size() == count && data() == ptr.
Throws: Nothing.
constexpr span(pointer first, pointer last);
Preconditions: [first, last) is a valid range.
If extent is not equal to dynamic_­extent, then last - first is equal to extent.
Effects: Constructs a span that is a view over the range [first, last).
Postconditions: 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;
Constraints:
  • extent == dynamic_­extent || N == extent is true, and
  • remove_­pointer_­t<decltype(data(arr))>(*)[] is convertible to ElementType(*)[].
Effects: Constructs a span that is a view over the supplied array.
Postconditions: size() == N && data() == data(arr).
template<class Container> constexpr span(Container& cont); template<class Container> constexpr span(const Container& cont);
Constraints:
  • extent == dynamic_­extent is true,
  • 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(*)[].
Preconditions: [data(cont), data(cont) + size(cont)) is a valid range.
Effects: Constructs a span that is a view over the range [data(cont), data(cont) + size(cont)).
Postconditions: size() == size(cont) && data() == data(cont).
Throws: What and when data(cont) and size(cont) throw.
constexpr span(const span& other) noexcept = default;
Postconditions: other.size() == size() && other.data() == data().
template<class OtherElementType, size_t OtherExtent> constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;
Constraints:
  • Extent == dynamic_­extent || Extent == OtherExtent is true, and
  • OtherElementType(*)[] is convertible to ElementType(*)[].
Effects: Constructs a span that is a view over the range [s.data(), s.data() + s.size()).
Postconditions: size() == s.size() && data() == s.data().
constexpr span& operator=(const span& other) noexcept = default;
Postconditions: size() == other.size() && data() == other.data().