24 Containers library [containers]

24.7 Views [views]

24.7.2 Contiguous access [views.contiguous]

24.7.2.2 Class template span [views.span]

24.7.2.2.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>>.
  • is_convertible_v<U(*)[], element_type(*)[]> is true.
    [Note 1: 
    The intent is to allow only qualification conversions of the iterator reference type to element_type.
    — end note]
Preconditions:
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 2: 
    The intent is to allow only qualification conversions of the iterator reference type to element_type.
    — end note]
  • End satisfies sized_sentinel_for<It>.
  • is_convertible_v<End, size_t> is false.
Preconditions:
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(std​::​data(arr))>.
  • extent == dynamic_extent || N == extent is true, and
  • is_convertible_v<U(*)[], element_type(*)[]> is true.
    [Note 3: 
    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 4: 
type_identity_t affects class template argument deduction.
— end note]
Postconditions: size() == N && data() == std​::​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 5: 
    The intent is to allow only qualification conversions of the range reference type to element_type.
    — end note]
Preconditions:
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 explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il);
Constraints: is_const_v<element_type> is true.
Preconditions: If extent is not equal to dynamic_extent, then il.size() is equal to extent.
Effects: Initializes data_ with il.begin() and size_ with il.size().
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 6: 
    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().