DUNE PDELab (git)

Dune::Std::span< Element, Extent > Class Template Reference

A contiguous sequence of elements with static or dynamic extent. More...

#include <dune/common/std/span.hh>

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 spanoperator= (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. More...
 
constexpr span< element_type, Std::dynamic_extentfirst (size_type count) const
 Obtains a subspan consisting of the first count elements of the sequence.
 
constexpr span< element_type, Std::dynamic_extentlast (size_type count) const
 Obtains a subspan consisting of the last count elements of the sequence.
 
constexpr span< element_type, Std::dynamic_extentsubspan (size_type offset, size_type count=Std::dynamic_extent) const
 Obtains a subspan consisting of count elements of the sequence starting at offset. More...
 

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.
 

Detailed Description

template<class Element, std::size_t Extent = Std::dynamic_extent>
class Dune::Std::span< Element, Extent >

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:

std::vector v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// view data as contiguous memory representing 10 elements
auto s1 = Dune::Std::span(v.data(), 10);
// view data as contiguous memory with static size
auto s2 = Dune::Std::span<int,10>(v.data());
// write data using 2D view
for (std::size_t i = 0; i != s1.size(); i++)
s1[i] = 2*i;
A contiguous sequence of elements with static or dynamic extent.
Definition: span.hh:126
Template Parameters
ElementThe element type; a complete object type that is not an abstract class type.
ExtentSpecifies number of elements in the sequence, or Std::dynamic_extent if dynamic.

Member Function Documentation

◆ subspan() [1/2]

template<class Element , std::size_t Extent = Std::dynamic_extent>
template<std::size_t Offset, std::size_t Count = Std::dynamic_extent>
constexpr span< element_type, subspan_extent(Offset, Count)> Dune::Std::span< Element, Extent >::subspan ( ) const
inlineconstexpr

Obtains a subspan consisting of Count elements of the sequence starting at Offset.

Note
If Count == Std::dynamic_extent, the subspan starting at Offset goes until the end of the current span.

References Dune::Std::span< Element, Extent >::data(), and Dune::Std::dynamic_extent.

◆ subspan() [2/2]

template<class Element , std::size_t Extent = Std::dynamic_extent>
constexpr span< element_type, Std::dynamic_extent > Dune::Std::span< Element, Extent >::subspan ( size_type  offset,
size_type  count = Std::dynamic_extent 
) const
inlineconstexpr

Obtains a subspan consisting of count elements of the sequence starting at offset.

Note
If count == Std::dynamic_extent, the subspan starting at offset goes until the end of the current span.

The documentation for this class was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 12, 23:30, 2024)