#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 of ptrdiff_t rather than size_t.

Template Parameters:
typename T

Element type, must be a valid array element type. May be const or volatile 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 pointer = T*;

Pointer to an element.

using const_pointer = const T*;

Pointer to a const-qualified element.

using reference = T&;

Reference to an element.

using const_reference = const T&;

Reference to a const-qualified element.

using iterator = pointer;

Iterator type.

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

constexpr const ptrdiff_t extent = Extent;

Static extent.

Constructors

constexpr span();

Constructs an empty/invalid array.

constexpr span(pointer ptrindex_type count);

Constructs from the specified pointer and length.

constexpr span(pointer beginpointer end);

Constructs from begin and end pointers.

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(Containercont);
constexpr span(const Containercont);

Constructs from a container with data and size methods.

constexpr span(const span<U, N>other);

Converts from a compatible span type.

Methods

constexpr pointer data() const noexcept;

Returns a pointer to the first element.

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 specified Count.

constexpr span<element_type, dynamic_extent>
subspan(ptrdiff_t offsetptrdiff_t count = dynamic_extent) const;

Returns a dynamic extent subspan from the starting offset and specified count.

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.

constexpr reference front() const;

Returns a reference to the first element.

constexpr reference back() const;

Returns a reference to the last element.

constexpr const ptrdiff_t tensorstore::dynamic_extent = -1;

Indicates that the extent is specified at run time.

std::integral_constant<ptrdiff_t, N>
tensorstore::GetStaticOrDynamicExtent(span<X, N>);
ptrdiff_t tensorstore::GetStaticOrDynamicExtent(span<X> s);

Returns the size of span as an std::integral_constant or DimensionIndex.

std::ostream&
tensorstore::operator<<(std::ostreamos,
                        
::tensorstore::span<Element, N> s);

Prints a string representation of a span.