[span.overview]

# 23 Containers library [[containers]](./#containers)

## 23.7 Views [[views]](views#span.overview)

### 23.7.2 Contiguous access [[views.contiguous]](views.contiguous#span.overview)

#### 23.7.2.2 Class template span [[views.span]](views.span#span.overview)

#### 23.7.2.2.1 Overview [span.overview]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20218)

A span is a view over a contiguous sequence of objects,
the storage of which is owned by some other object[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20223)

All member functions of span have constant time complexity[.](#2.sentence-1)

[ð](#lib:span_)

namespace std {template<class ElementType, size_t Extent = dynamic_extent>class span {public:// constants and typesusing element_type = ElementType; using value_type = remove_cv_t<ElementType>; using size_type = size_t; using difference_type = ptrdiff_t; using pointer = element_type*; using const_pointer = const element_type*; using reference = element_type&; using const_reference = const element_type&; using iterator = *implementation-defined*; // see [[span.iterators]](span.iterators "23.7.2.2.7 Iterator support")using const_iterator = std::const_iterator<iterator>; using reverse_iterator = std::reverse_iterator<iterator>; using const_reverse_iterator = std::const_iterator<reverse_iterator>; static constexpr size_type extent = Extent; // [[span.cons]](span.cons "23.7.2.2.2 Constructors, copy, and assignment"), constructors, copy, and assignmentconstexpr span() noexcept; template<class It>constexpr explicit(extent != dynamic_extent) span(It first, size_type count); template<class It, class End>constexpr explicit(extent != dynamic_extent) span(It first, End last); 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; template<class R>constexpr explicit(extent != dynamic_extent) span(R&& r); constexpr explicit(extent != dynamic_extent) span(std::initializer_list<value_type> il); constexpr span(const span& other) noexcept = default; template<class OtherElementType, size_t OtherExtent>constexpr explicit(*see below*) span(const span<OtherElementType, OtherExtent>& s) noexcept; constexpr span& operator=(const span& other) noexcept = default; // [[span.sub]](span.sub "23.7.2.2.4 Subviews"), subviewstemplate<size_t Count>constexpr span<element_type, Count> first() const; template<size_t Count>constexpr span<element_type, Count> last() const; template<size_t Offset, size_t Count = dynamic_extent>constexpr span<element_type, *see below*> subspan() const; constexpr span<element_type, dynamic_extent> first(size_type count) const; constexpr span<element_type, dynamic_extent> last(size_type count) const; constexpr span<element_type, dynamic_extent> subspan( size_type offset, size_type count = dynamic_extent) const; // [[span.obs]](span.obs "23.7.2.2.5 Observers"), observersconstexpr size_type size() const noexcept; constexpr size_type size_bytes() const noexcept; constexpr bool empty() const noexcept; // [[span.elem]](span.elem "23.7.2.2.6 Element access"), element accessconstexpr reference operator[](size_type idx) const; constexpr reference at(size_type idx) const; // freestanding-deletedconstexpr reference front() const; constexpr reference back() const; constexpr pointer data() const noexcept; // [[span.iterators]](span.iterators "23.7.2.2.7 Iterator support"), iterator supportconstexpr iterator begin() const noexcept; constexpr iterator end() const noexcept; constexpr const_iterator cbegin() const noexcept { return begin(); }constexpr const_iterator cend() const noexcept { return end(); }constexpr reverse_iterator rbegin() const noexcept; constexpr reverse_iterator rend() const noexcept; constexpr const_reverse_iterator crbegin() const noexcept { return rbegin(); }constexpr const_reverse_iterator crend() const noexcept { return rend(); }private: pointer *data_*; // *exposition only* size_type *size_*; // *exposition only*}; template<class It, class EndOrSize> span(It, EndOrSize) -> span<remove_reference_t<iter_reference_t<It>>, [*maybe-static-ext*](span.syn#concept:maybe-static-ext "23.7.2.1 Header <span> synopsis [span.syn]")<EndOrSize>>; template<class T, size_t N> span(T (&)[N]) -> span<T, N>; template<class T, size_t N> span(array<T, N>&) -> span<T, N>; template<class T, size_t N> span(const array<T, N>&) -> span<const T, N>; template<class R> span(R&&) -> span<remove_reference_t<ranges::range_reference_t<R>>>;}

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20322)

span<ElementType, Extent> is
a trivially copyable type ([[basic.types.general]](basic.types.general#term.trivially.copyable.type "6.9.1 General"))[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20326)

ElementType is required to be
a complete object type that is not an abstract class type[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L20330)

For a span s,
any operation that invalidates a pointer in
the range [s.data(), s.data() + s.size())
invalidates pointers, iterators, and references to elements of s[.](#5.sentence-1)
