12 KiB
[span.cons]
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 satisfies contiguous_iterator.
-
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.
-
It models contiguous_iterator.
Hardened preconditions: If extent is not equal to dynamic_extent, then count == extent is true.
Effects: Initializes data_ with to_address(first) andsize_ 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>.
-
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]
-
It satisfies contiguous_iterator.
-
End satisfies sized_sentinel_for.
-
is_convertible_v<End, size_t> is false.
Preconditions:
-
[first, last) is a valid range.
-
It models contiguous_iterator.
-
End models sized_sentinel_for.
Hardened preconditions: If extent is not equal to dynamic_extent, then (last - first) == extent is true.
Effects: Initializes data_ with to_address(first) andsize_ 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 satisfies ranges::contiguous_range and ranges::sized_range.
-
Either R satisfies ranges::borrowed_range oris_const_v<element_type> is true.
-
remove_cvref_t is not a specialization of span.
-
remove_cvref_t is not a specialization of array.
-
is_array_v<remove_cvref_t> 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:
-
R models ranges::contiguous_range andranges::sized_range.
-
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) andsize_ 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() andsize_ 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().