std::span<T,Extent>::span (3) - Linux Manuals

std::span<T,Extent>::span: std::span<T,Extent>::span

NAME

std::span<T,Extent>::span - std::span<T,Extent>::span

Synopsis


constexpr span() noexcept; (1)
constexpr span(pointer ptr, index_type count); (2)
constexpr span(pointer first, pointer last); (3)
template <std::size_t N> (4)
constexpr span(element_type (&arr)[N]) noexcept;
template <std::size_t N> (5)
constexpr span(std::array<value_type, N>& arr) noexcept;
template <std::size_t N> (6)
constexpr span(const std::array<value_type, N>& arr) noexcept;
template <class Container> (7)
constexpr span(Container& cont);
template <class Container> (8)
constexpr span(const Container& cont);
template <class U, std::size_t N> (9)
constexpr span(const std::span<U, N>& s) noexcept;
constexpr span(const span& other) noexcept = default; (10)


Constructs a span.
1) Constructs an empty span whose data() == nullptr and size() == 0. This overload only participates in overload resolution if extent == 0 || extent == std::dynamic_extent.
2) Constructs a span that is a view over the range [ptr, ptr + count); the resulting span has data() == ptr and size() == count. The behavior is undefined if [ptr, ptr + count) is not a valid range or if extent != std::dynamic_extent && count != extent.
3) Constructs a span that is a view over the range [first, last); equivalent to span(first, last - first).
4-6) Constructs a span that is a view over the array arr; the resulting span has size() == N and data() == std::data(arr). These overloads only participate in overload resolution if extent == std::dynamic_extent || N == extent is true and std::remove_pointer_t<decltype(std::data(arr))>(*)[] is convertible to element_type (*)[]
7-8) Constructs a span that is a view over the range [std::data(cont), std::data(cont) + std::size(cont)); the resulting span has size() == std::size(cont) and data() == std::data(cont). The behavior is undefined if that is not a valid range or if extent != std::dynamic_extent && std::size(cont) != extent.
These overloads only participate in overload resolution if


      * Container is not a specialization of std::span, a specialization of std::array, or an array type;
      * std::data(cont) and std::size(cont) are both well-formed; and
      * std::remove_pointer_t<decltype(std::data(cont))>(*)[] is convertible to element_type (*)[]


9) Converting constructor from another span s; the resulting span has size() == s.size() and data() == s.data(). This overload only participates in overload resolution if extent == std::dynamic_extent || N == extent is true and U (*)[] is convertible to element_type (*)[].
10) Defaulted copy constructor copies the size and data pointer; the resulting span has size() == other.size() and data() == other.data().

Parameters


ptr, first - pointer to the first element of the sequence
count - number of elements in the sequence
last - pointer past the last element of the sequence
arr - array to construct a view for
cont - container to construct a view for
s - another span to convert from
other - another span to copy from

Exceptions


2-3) Throws nothing.
7-8) Throws what and when std::size(cont) and std::data(cont) throw.

See also


          returns a pointer to the beginning of the sequence of elements
data (public member function)
          returns the number of elements in the sequence
size (public member function)
          assigns a span
operator= (public member function)


size
ssize returns the size of a container or array
          (function template)
(C++17)
(C++20)


data obtains the pointer to the underlying array
          (function template)
(C++17)