|
dune-common 2.10
|
A contiguous sequence of elements with static or dynamic extent. More...
#include <dune/common/std/span.hh>

Public Types | |
| using | element_type = Element |
| using | value_type = std::remove_cv_t<element_type> |
| using | size_type = std::size_t |
| using | difference_type = std::ptrdiff_t |
| using | pointer = element_type* |
| using | reference = element_type& |
| using | const_reference = const element_type& |
| using | iterator = pointer |
| using | reverse_iterator = std::reverse_iterator<iterator> |
| using | const_iterator = const iterator |
| using | const_reverse_iterator = std::reverse_iterator<const_iterator> |
Static Public Attributes | |
| static constexpr size_type | extent = Extent |
Span constructors | |
| template<std::size_t e = extent, std::enable_if_t<(e==dynamic_extent||e==0), int > = 0> | |
| constexpr | span () noexcept |
| Default construct an empty span. | |
| template<class Iter, class U = std::remove_reference_t<decltype(*std::declval<Iter>())>, std::enable_if_t< std::is_convertible_v< U(*)[], element_type(*)[]>, int > = 0> | |
| constexpr | span (Iter first, size_type size) |
| Constructs a span that is a view over the range [first, first+size). | |
| template<class Iter, class U = std::remove_reference_t<decltype(*std::declval<Iter>())>, std::enable_if_t< std::is_convertible_v< U(*)[], element_type(*)[]>, int > = 0> | |
| constexpr | span (Iter first, Iter last) |
| Constructs a span that is a view over the range [first, last). | |
| template<class Range, decltype(std::begin(std::declval< Range >()), std::end(std::declval< Range >()), bool{}) = true, std::enable_if_t< not std::is_array_v< Range >, int > = 0> | |
| constexpr | span (Range &range) |
| Constructs a span that is a view over the range [range.begin(), range.end()). | |
| template<std::size_t N, std::size_t e = extent, std::enable_if_t<(e==Std::dynamic_extent||e==N), int > = 0> | |
| constexpr | span (Impl::TypeIdentity_t< element_type >(&data)[N]) noexcept |
| Constructs a span that is a view over the C-array. | |
| template<class T, size_t N, std::size_t e = extent, std::enable_if_t<(e==Std::dynamic_extent||e==N), int > = 0, std::enable_if_t< std::is_convertible_v< T(*)[], element_type(*)[]>, int > = 0> | |
| constexpr | span (std::array< T, N > &arr) noexcept |
| Constructs a span that is a view over the array. | |
| template<class T, size_t N, std::size_t e = extent, std::enable_if_t<(e==Std::dynamic_extent||e==N), int > = 0, std::enable_if_t< std::is_convertible_v< const T(*)[], element_type(*)[]>, int > = 0> | |
| constexpr | span (const std::array< T, N > &arr) noexcept |
| Constructs a span that is a view over the const array. | |
| template<class E = element_type, std::enable_if_t< std::is_const_v< E >, int > = 0> | |
| constexpr | span (std::initializer_list< value_type > il) |
| Constructs a span that is a view over the initializer-list. | |
| constexpr | span (const span &other) noexcept=default |
| Copy constructor. | |
| template<class OtherElementType, std::size_t OtherExtent, std::enable_if_t<(extent==Std::dynamic_extent||OtherExtent==Std::dynamic_extent||extent==OtherExtent), int > = 0, std::enable_if_t< std::is_convertible_v< OtherElementType(*)[], element_type(*)[]>, int > = 0> | |
| constexpr | span (const span< OtherElementType, OtherExtent > &s) noexcept |
| Converting copy constructor. | |
| constexpr span & | operator= (const span &other) noexcept=default |
| Copy assignment operator. | |
Iterators | |
| constexpr iterator | begin () const noexcept |
| Returns an iterator to the beginning. | |
| constexpr iterator | end () const noexcept |
| Returns an iterator to the end. | |
| constexpr const_iterator | cbegin () const noexcept |
| Returns an iterator to the beginning. | |
| constexpr const_iterator | cend () const noexcept |
| Returns an iterator to the end. | |
| constexpr reverse_iterator | rbegin () const noexcept |
| Returns a reverse iterator starting at the end. | |
| constexpr reverse_iterator | rend () const noexcept |
| Returns a reverse iterator ending at the beginning. | |
| constexpr const_reverse_iterator | crbegin () const noexcept |
| Returns a reverse iterator starting at the end. | |
| constexpr const_reverse_iterator | crend () const noexcept |
| Returns a reverse iterator ending at the beginning. | |
Element and data access | |
| constexpr reference | front () const |
| Access the first element. | |
| constexpr reference | back () const |
| Access the last element. | |
| constexpr reference | at (size_type i) const |
| Access specified element with bounds checking. | |
| constexpr reference | operator[] (size_type i) const |
| Access specified element. | |
| constexpr pointer | data () const noexcept |
| Direct access to the underlying contiguous storage. | |
Subspans | |
| template<std::size_t Count> | |
| constexpr span< element_type, Count > | first () const |
| Obtains a subspan consisting of the first Count elements of the sequence. | |
| template<std::size_t Count> | |
| constexpr span< element_type, Count > | last () const |
| Obtains a subspan consisting of the last Count elements of the sequence. | |
| template<std::size_t Offset, std::size_t Count = Std::dynamic_extent> | |
| constexpr span< element_type, subspan_extent(Offset, Count)> | subspan () const |
| Obtains a subspan consisting of Count elements of the sequence starting at Offset. | |
| constexpr span< element_type, Std::dynamic_extent > | first (size_type count) const |
| Obtains a subspan consisting of the first count elements of the sequence. | |
| constexpr span< element_type, Std::dynamic_extent > | last (size_type count) const |
| Obtains a subspan consisting of the last count elements of the sequence. | |
| constexpr span< element_type, Std::dynamic_extent > | subspan (size_type offset, size_type count=Std::dynamic_extent) const |
| Obtains a subspan consisting of count elements of the sequence starting at offset. | |
Size information | |
| constexpr size_type | size_bytes () const noexcept |
| Returns the size of the sequence in bytes. | |
| constexpr bool | empty () const noexcept |
| Checks if the sequence is empty. | |
A contiguous sequence of elements with static or dynamic extent.
The class template span describes an object that can refer to a contiguous sequence of objects with the first element of the sequence at position zero. A span can either have a static extent, in which case the number of elements in the sequence is known at compile-time and encoded in the type, or a dynamic extent.
If a span has dynamic extent, a typical implementation holds two members: a pointer to Element and a size. A span with static extent may have only one member: a pointer to Element.
The implementation is based on the C++ standard working draft N4971 and the documentation provided in cppreference.
Example:
| Element | The element type; a complete object type that is not an abstract class type. |
| Extent | Specifies number of elements in the sequence, or Std::dynamic_extent if dynamic. |
| using Dune::Std::span< Element, Extent >::const_iterator = const iterator |
| using Dune::Std::span< Element, Extent >::const_reference = const element_type& |
| using Dune::Std::span< Element, Extent >::const_reverse_iterator = std::reverse_iterator<const_iterator> |
| using Dune::Std::span< Element, Extent >::difference_type = std::ptrdiff_t |
| using Dune::Std::span< Element, Extent >::element_type = Element |
| using Dune::Std::span< Element, Extent >::iterator = pointer |
| using Dune::Std::span< Element, Extent >::pointer = element_type* |
| using Dune::Std::span< Element, Extent >::reference = element_type& |
| using Dune::Std::span< Element, Extent >::reverse_iterator = std::reverse_iterator<iterator> |
| using Dune::Std::span< Element, Extent >::size_type = std::size_t |
| using Dune::Std::span< Element, Extent >::value_type = std::remove_cv_t<element_type> |
|
inlineconstexprnoexcept |
Default construct an empty span.
|
inlineconstexpr |
Constructs a span that is a view over the range [first, first+size).
|
inlineconstexpr |
|
inlineconstexpr |
Constructs a span that is a view over the range [range.begin(), range.end()).
|
inlineconstexprnoexcept |
Constructs a span that is a view over the C-array.
|
inlineconstexprnoexcept |
Constructs a span that is a view over the array.
|
inlineconstexprnoexcept |
Constructs a span that is a view over the const array.
|
inlineconstexpr |
Constructs a span that is a view over the initializer-list.
|
constexprdefaultnoexcept |
Copy constructor.
|
inlineconstexprnoexcept |
Converting copy constructor.
|
inlineconstexpr |
Access specified element with bounds checking.
|
inlineconstexpr |
Access the last element.
|
inlineconstexprnoexcept |
Returns an iterator to the beginning.
|
inlineconstexprnoexcept |
Returns an iterator to the beginning.
|
inlineconstexprnoexcept |
Returns an iterator to the end.
|
inlineconstexprnoexcept |
Returns a reverse iterator starting at the end.
|
inlineconstexprnoexcept |
Returns a reverse iterator ending at the beginning.
|
inlineconstexprnoexcept |
Direct access to the underlying contiguous storage.
|
inlinenodiscardconstexprnoexcept |
Checks if the sequence is empty.
|
inlineconstexprnoexcept |
Returns an iterator to the end.
|
inlineconstexpr |
Obtains a subspan consisting of the first Count elements of the sequence.
|
inlineconstexpr |
Obtains a subspan consisting of the first count elements of the sequence.
|
inlineconstexpr |
Access the first element.
|
inlineconstexpr |
Obtains a subspan consisting of the last Count elements of the sequence.
|
inlineconstexpr |
Obtains a subspan consisting of the last count elements of the sequence.
|
constexprdefaultnoexcept |
Copy assignment operator.
|
inlineconstexpr |
Access specified element.
|
inlineconstexprnoexcept |
Returns a reverse iterator starting at the end.
|
inlineconstexprnoexcept |
Returns a reverse iterator ending at the beginning.
|
inlineconstexprnoexcept |
Returns the size of the sequence in bytes.
|
inlineconstexpr |
Obtains a subspan consisting of Count elements of the sequence starting at Offset.
|
inlineconstexpr |
Obtains a subspan consisting of count elements of the sequence starting at offset.
|
staticconstexpr |