[span.cons] (original) (raw)
23 Containers library [containers]
23.7 Views [views]
23.7.2 Contiguous access [views.contiguous]
23.7.2.2 Class template span [views.span]
23.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:
- [first, first + count) is a valid range.
Hardened preconditions: If extent is not equal to dynamic_extent, then count == extent is true.
Effects: Initializes data_ with to_address(first) and_size__ with count.
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_] - is_convertible_v<End, size_t> is false.
Preconditions:
- [first, last) is a valid range.
Hardened preconditions: If extent is not equal to dynamic_extent, then (last - first) == extent is true.
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>>.
- Either R satisfies ranges::borrowed_range oris_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:
- If is_const_v<element_type> is false,R models ranges::borrowed_range.
Hardened preconditions: If extent is not equal to dynamic_extent, then ranges::size(r) == extent is true.
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.
Hardened preconditions: If extent is not equal to dynamic_extent, then il.size() == extent is true.
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_]
Hardened preconditions: If extent is not equal to dynamic_extent, then s.size() == extent is true.
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().