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.
template<class It> constexpr explicit(extent != dynamic_extent) span(It first, size_type count);
Constraints: Let U be remove_­reference_­t<iter_­reference_­t<It>>.
  • It satisfies contiguous_­iterator.
  • is_­convertible_­v<U(*)[], element_­type(*)[]> is true.
    [Note:
    The intent is to allow only qualification conversions of the iterator reference type to element_­type.
    — end note]
Preconditions:
  • [first, first + count) is a valid range.
  • It models contiguous_­iterator.
  • If extent is not equal to dynamic_­extent, then count is equal to extent.
Effects: Initializes data_­ with to_­address(first) and size_­ with count.
Throws: Nothing.
template<class It, class End> constexpr explicit(extent != dynamic_extent) span(It first, End last);
Constraints: Let U be remove_­reference_­t<iter_­reference_­t<It>>.
  • is_­convertible_­v<U(*)[], element_­type(*)[]> is true.
    [Note:
    The intent is to allow only qualification conversions of the iterator reference type to element_­type.
    — end note]
  • It satisfies contiguous_­iterator.
  • End satisfies sized_­sentinel_­for<It>.
  • is_­convertible_­v<End, size_­t> is false.
Preconditions:
  • If extent is not equal to dynamic_­extent, then last - first is equal to extent.
  • [first, last) is a valid range.
  • It models contiguous_­iterator.
  • End models sized_­sentinel_­for<It>.
Effects: Initializes data_­ with to_­address(first) and size_­ with last - first.
Throws: When and what last - first throws.
template<size_t N> constexpr span(type_identity_t<element_type> (&arr)[N]) noexcept; template<class T, size_t N> constexpr span(array<T, N>& arr) noexcept; template<class T, size_t N> constexpr span(const array<T, N>& arr) noexcept;
Constraints: Let U be remove_­pointer_­t<decltype(data(arr))>.
  • extent == dynamic_­extent || N == extent is true, and
  • is_­convertible_­v<U(*)[], element_­type(*)[]> is true.
    [Note:
    The intent is to allow only qualification conversions of the array element type to element_­type.
    — end note]
Effects: Constructs a span that is a view over the supplied array.
[Note:
type_­identity_­t affects class template argument deduction.
— end note]
Postconditions: size() == N && data() == data(arr) is true.
template<class R> constexpr explicit(extent != dynamic_extent) span(R&& r);
Constraints: Let U be remove_­reference_­t<ranges​::​range_­reference_­t<R>>.
  • R satisfies ranges​::​contiguous_­range and ranges​::​sized_­range.
  • Either R satisfies ranges​::​borrowed_­range or is_­const_­v<element_­type> is true.
  • remove_­cvref_­t<R> is not a specialization of span.
  • remove_­cvref_­t<R> is not a specialization of array.
  • is_­array_­v<remove_­cvref_­t<R>> is false.
  • is_­convertible_­v<U(*)[], element_­type(*)[]> is true.
    [Note:
    The intent is to allow only qualification conversions of the range reference type to element_­type.
    — end note]
Preconditions:
  • If extent is not equal to dynamic_­extent, then ranges​::​size(r) is equal to extent.
  • R models ranges​::​contiguous_­range and ranges​::​sized_­range.
  • If is_­const_­v<element_­type> is false, R models ranges​::​borrowed_­range.
Effects: Initializes data_­ with ranges​::​data(r) and size_­ with ranges​::​size(r).
Throws: What and when ranges​::​data(r) and ranges​::​size(r) throw.
constexpr span(const span& other) noexcept = default;
Postconditions: other.size() == size() && other.data() == data().
template<class OtherElementType, size_t OtherExtent> constexpr explicit(see below) span(const span<OtherElementType, OtherExtent>& s) noexcept;
Constraints:
  • extent == dynamic_­extent || OtherExtent == dynamic_­extent || extent == OtherExtent is true, and
  • is_­convertible_­v<OtherElementType(*)[], element_­type(*)[]> is true.
    [Note:
    The intent is to allow only qualification conversions of the OtherElementType to element_­type.
    — end note]
Preconditions: If extent is not equal to dynamic_­extent, then s.size() is equal to extent.
Effects: Constructs a span that is a view over the range [s.data(), s.data() + s.size()).
Postconditions: size() == s.size() && data() == s.data().
Remarks: The expression inside explicit is equivalent to:
extent != dynamic_extent && OtherExtent == dynamic_extent
constexpr span& operator=(const span& other) noexcept = default;
Postconditions: size() == other.size() && data() == other.data().