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

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

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
(public member function)
returns the number of elements in the sequence
(public member function)
assigns a span
(public member function)
(C++17)(C++20)
returns the size of a container or array
(function template)
(C++17)
obtains the pointer to the underlying array
(function template)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/container/span/span