-
#include "tensorstore/util/span.h"
-
template <typename T, ptrdiff_t Extent>
class tensorstore::span; Unowned view of a contiguous 1-d array of elements, similar to
std::span
.Note
This class is nearly identical to
std::span
; the main difference is that in this implementation,size
has a signed return type ofptrdiff_t
rather thansize_t
.- Template Parameters:¶
- typename T¶
Element type, must be a valid array element type. May be
const
orvolatile
qualified, but must not be a reference type.- ptrdiff_t Extent¶
Static extent of the array, or
dynamic_extent
to indicate that the extent is specified at run time.
Types¶
- using element_type = T;
Element type of the array.
- using value_type = std::remove_cv_t<T>;
Unqualified element type.
- using index_type = ptrdiff_t;
Type used for indexing.
- using difference_type = ptrdiff_t;
Type used for indexing.
- using const_pointer = const T*;
Pointer to a const-qualified element.
- using const_reference = const T&;
Reference to a const-qualified element.
- using const_iterator = const_pointer;
Constant iterator type.
- using reverse_iterator = std::reverse_iterator<iterator>;
Reverse iterator type.
- using const_reverse_iterator = std::reverse_iterator<const_iterator>;
Constant reverse iterator type.
Data members¶
Constructors¶
- constexpr span();
Constructs an empty/invalid array.
- constexpr span(pointer ptr, index_type count);
Constructs from the specified pointer and length.
- constexpr span(T (&arr)[N]);
- constexpr span(std::array<value_type, N>& arr);
- constexpr span(const std::array<value_type, N>& arr);
Constructs from an array or
std::array
.
- constexpr span(Container& cont);
- constexpr span(const Container& cont);
Constructs from a container with
data
andsize
methods.
Methods¶
- constexpr index_type size() const noexcept;
Returns the size.
- constexpr bool empty() const noexcept;
Returns true if the span is empty.
- constexpr index_type size_bytes() const noexcept;
Returns the size in bytes.
- constexpr iterator begin() const noexcept;
- constexpr iterator end() const noexcept;
- constexpr const_iterator cbegin() const noexcept;
- constexpr const_iterator cend() const noexcept;
Returns begin/end iterators.
- constexpr reverse_iterator rbegin() const noexcept;
- constexpr const_reverse_iterator crbegin() const noexcept;
- constexpr reverse_iterator rend() const noexcept;
- constexpr const_reverse_iterator crend() const noexcept;
Returns begin/end reverse iterators.
- constexpr span<element_type, Count> first() const;
Returns a static extent subspan of the first
Count
elements.
-
constexpr span<element_type, dynamic_extent>
first(ptrdiff_t count) const; Returns a dynamic extent subspan of the first
count
elements.
- constexpr span<element_type, Count> last() const;
Returns a static extent subspan of the last
Count
elements.
-
constexpr span<element_type, dynamic_extent>
last(ptrdiff_t count) const; Returns a dynamic extent subspan of the last
count
elements.
- constexpr auto subspan() const;
Returns a subspan from the starting offset
Offset
with the specifiedCount
.
-
constexpr span<element_type, dynamic_extent>
subspan(ptrdiff_t offset, ptrdiff_t count = dynamic_extent) const; Returns a dynamic extent subspan from the starting
offset
and specifiedcount
.
- constexpr reference operator[](index_type i) const noexcept;
Returns a reference to the element at the specified index.
- constexpr reference at(index_type i) const;
Returns a reference to the element at the specified index.
Related Constants¶
- constexpr const ptrdiff_t tensorstore::dynamic_extent = -1;
Indicates that the extent is specified at run time.
Related Functions¶
-
std::integral_constant<ptrdiff_t, N>
tensorstore::GetStaticOrDynamicExtent(span<X, N>); - ptrdiff_t tensorstore::GetStaticOrDynamicExtent(span<X> s);
Returns the size of
span
as anstd::integral_constant
orDimensionIndex
.
-
std::ostream&
tensorstore::operator<<(std::ostream& os,
::tensorstore::span<Element, N> s); Prints a string representation of a span.