Finite Volume Solver  prototype
A framework to build finite volume solvers for the AG Klein at the Freie Universität Berlin.
Public Types | Static Public Attributes | List of all members
fub::span< T, N > Class Template Reference

A span is a view over a contiguous sequence of objects, the storage of which is owned by some other object. More...

#include <span.hpp>

Public Types

using element_type = T
 
using pointer = T *
 
using reference = T &
 
using value_type = std::remove_cv_t< T >
 
using index_type = std::ptrdiff_t
 
using difference_type = std::ptrdiff_t
 
using iterator = pointer
 
using const_iterator = std::add_const_t< T > *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

Constructors, copy, and assignment [span.cons]
constexpr span (pointer p, [[maybe_unused]] index_type size)
 Constructs a span from a pointer and size pair. More...
 
constexpr span (pointer first, pointer last)
 Constructs a span from two pointers. More...
 
constexpr span (element_type(&arr)[sextent]) noexcept
 Implicit conversion from a built-in C-style array. More...
 
template<typename ValueType , std::size_t Extent, typename = std::enable_if_t<Extent == extent>, typename = std::enable_if_t<std::is_convertible< const ValueType (*)[], element_type (*)[]>::value>>
constexpr span (const std::array< ValueType, Extent > &arr) noexcept
 Implicit conversion from const std::arrays. More...
 
template<typename ValueType , std::size_t Extent, typename = std::enable_if_t<Extent == extent>, typename = std::enable_if_t<std::is_convertible< ValueType (*)[], element_type (*)[]>::value>>
constexpr span (std::array< ValueType, Extent > &arr) noexcept
 Implicit conversion from mutable std::arrays. More...
 
template<typename Container >
constexpr span (Container &container)
 Implicit conversion operator from a mutable container. More...
 
template<typename Container >
constexpr span (const Container &container)
 Implicit conversion operator from a constant container. More...
 
template<typename S , std::ptrdiff_t M>
constexpr span (const span< S, M > &s) noexcept
 Implicit conversion from other span types. More...
 
template<typename S , typename = std::enable_if_t<std::is_convertible< typename span<S>::element_type (*)[], element_type (*)[]>::value>>
constexpr span (const span< S > &s)
 Constructs a span from a pointer and size pair. More...
 
constexpr span (const span &s) noexcept=default
 Defaulted copy constructor to trivially copy the class member variables. More...
 
Subviews [span.sub]
template<ptrdiff_t Count, typename = std::enable_if_t<(0 <= Count && Count <= extent)>>
constexpr span< element_type, Count > first () const
 Returns a span of the first Count-many elements of this span. More...
 
constexpr span< element_typefirst (index_type count) const
 Returns a span of the first count-many elements of this span. More...
 
template<ptrdiff_t Count, typename = std::enable_if_t<(0 <= Count && Count <= extent)>>
constexpr span< element_type, Count > last () const
 Returns a span of the last Count-many elements of this span. More...
 
constexpr span< element_typelast (index_type count) const
 Returns a span of the last count-many elements of this span. More...
 
template<ptrdiff_t Offset, ptrdiff_t Count = dynamic_extent, typename = std::enable_if_t<(0 <= Offset && Offset <= extent)>, typename = std::enable_if_t<(Count == dynamic_extent || (0 <= Count && Count + Offset <= extent))>>
constexpr auto subspan () const
 Returns a subspan viewing Count many elements from offset Offset. More...
 
constexpr span< element_typesubspan (index_type offset, index_type count=dynamic_extent) const
 Returns a subspan viewing count many elements from offset offset. More...
 
Observers [span.obs]
constexpr index_type size () const noexcept
 Returns the number of elements in the span. More...
 
constexpr index_type size_bytes () const noexcept
 Returns the number of bytes which are spanned by this span. More...
 
constexpr bool empty () const noexcept
 Returns true if size() == 0. More...
 
Element access [span.elem]
constexpr pointer data () const noexcept
 Returns the underlying pointer. More...
 
constexpr reference operator[] (index_type n) const
 Accesses the n-th element of the spanned array. More...
 
constexpr reference operator() (index_type n) const
 Accesses the n-th element of the spanned array. More...
 

Static Public Attributes

static constexpr index_type extent
 
static constexpr std::size_t sextent
 

Iterator support [span.iterators]

pointer pointer_
 Returns an iterator pointing to the first element of the span. More...
 
constexpr iterator begin () const noexcept
 Returns an iterator pointing to the first element of the span. More...
 
constexpr const_iterator cbegin () const noexcept
 Returns a const iterator pointing to the first element of the span. More...
 
constexpr iterator end () const noexcept
 Returns an iterator pointing one after the last element of the span. More...
 
constexpr const_iterator cend () const noexcept
 Returns a const iterator pointing one after the last element of the span. More...
 
constexpr reverse_iterator rbegin () const noexcept
 Returns a reverse iterator pointing to the last element of the span. More...
 
constexpr const_reverse_iterator crbegin () const noexcept
 Returns a const reverse iterator pointing to the last element of the span. More...
 
constexpr reverse_iterator rend () const noexcept
 Returns a reverse iterator pointing to the first element of the span. More...
 
constexpr const_reverse_iterator crend () const noexcept
 Returns a const reverse iterator pointing to the first element of the span. More...
 

Detailed Description

template<typename T, std::ptrdiff_t N = dynamic_extent>
class fub::span< T, N >

A span is a view over a contiguous sequence of objects, the storage of which is owned by some other object.

All member functions of span have constant time complexity.

T is required to be a complete object type that is not an abstract class type.

If N is negative and not equal to dynamic_­extent, the program is ill-formed.

Member Typedef Documentation

◆ const_iterator

template<typename T , std::ptrdiff_t N = dynamic_extent>
using fub::span< T, N >::const_iterator = std::add_const_t<T>*

◆ const_reverse_iterator

template<typename T , std::ptrdiff_t N = dynamic_extent>
using fub::span< T, N >::const_reverse_iterator = std::reverse_iterator<const_iterator>

◆ difference_type

template<typename T , std::ptrdiff_t N = dynamic_extent>
using fub::span< T, N >::difference_type = std::ptrdiff_t

◆ element_type

template<typename T , std::ptrdiff_t N = dynamic_extent>
using fub::span< T, N >::element_type = T

◆ index_type

template<typename T , std::ptrdiff_t N = dynamic_extent>
using fub::span< T, N >::index_type = std::ptrdiff_t

◆ iterator

template<typename T , std::ptrdiff_t N = dynamic_extent>
using fub::span< T, N >::iterator = pointer

◆ pointer

template<typename T , std::ptrdiff_t N = dynamic_extent>
using fub::span< T, N >::pointer = T*

◆ reference

template<typename T , std::ptrdiff_t N = dynamic_extent>
using fub::span< T, N >::reference = T&

◆ reverse_iterator

template<typename T , std::ptrdiff_t N = dynamic_extent>
using fub::span< T, N >::reverse_iterator = std::reverse_iterator<iterator>

◆ value_type

template<typename T , std::ptrdiff_t N = dynamic_extent>
using fub::span< T, N >::value_type = std::remove_cv_t<T>

Constructor & Destructor Documentation

◆ span() [1/10]

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr fub::span< T, N >::span ( pointer  p,
[[maybe_unused] ] index_type  size 
)
inlineconstexpr

Constructs a span from a pointer and size pair.

This performs an assertion check in debug builds which will terminate the application if the specified size does not match the extent.

Parameters
[in]pa valid address pointing to the first element of the span.
[in]sizethe size such that [p, p + size) is a valid range.
Precondition
size == extent
Postcondition
data() == p
size() == size
Exceptions
Nothing.

◆ span() [2/10]

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr fub::span< T, N >::span ( pointer  first,
pointer  last 
)
inlineconstexpr

Constructs a span from two pointers.

This performs an assertion check in debug builds which will terminate the application if the specified size does not match the extent.

Parameters
[in]firsta valid address pointing to the first element of the span.
[in]lasta pointer such that [first, last) is a valid range.
Precondition
last - first == extent
Postcondition
data() == first
size() == last - first
Exceptions
Nothing.

◆ span() [3/10]

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr fub::span< T, N >::span ( element_type(&)  arr[sextent])
inlineconstexprnoexcept

Implicit conversion from a built-in C-style array.

Parameters
[in]arrA native array which will be viewed on.
Postcondition
data() = &arr[0]
size() == extent
Exceptions
Nothing.

◆ span() [4/10]

template<typename T , std::ptrdiff_t N = dynamic_extent>
template<typename ValueType , std::size_t Extent, typename = std::enable_if_t<Extent == extent>, typename = std::enable_if_t<std::is_convertible< const ValueType (*)[], element_type (*)[]>::value>>
constexpr fub::span< T, N >::span ( const std::array< ValueType, Extent > &  arr)
inlineconstexprnoexcept

Implicit conversion from const std::arrays.

Parameters
[in]arrA std::array which will be viewed on.
Precondition
std::is_const<element_type>
Postcondition
data() = arr.data()
size() == extent
Exceptions
Nothing.

◆ span() [5/10]

template<typename T , std::ptrdiff_t N = dynamic_extent>
template<typename ValueType , std::size_t Extent, typename = std::enable_if_t<Extent == extent>, typename = std::enable_if_t<std::is_convertible< ValueType (*)[], element_type (*)[]>::value>>
constexpr fub::span< T, N >::span ( std::array< ValueType, Extent > &  arr)
inlineconstexprnoexcept

Implicit conversion from mutable std::arrays.

Parameters
[in]arrA std::array which will be viewed on.
Precondition
M == extent
Postcondition
data() = arr.data()
size() == extent
Exceptions
Nothing.

◆ span() [6/10]

template<typename T , std::ptrdiff_t N = dynamic_extent>
template<typename Container >
constexpr fub::span< T, N >::span ( Container &  container)
inlineconstexpr

Implicit conversion operator from a mutable container.

Parameters
[in]containerA container which owns the contiguous memory. The container must outlive this span, otherwise the span is dangling.
Template Parameters
ContainerA container class which has the class member functions Container::data() and Container::size().
Precondition
container.size() == extent
!is_span_v<Container>
Postcondition
data() == container.data()
size() == container.size() == extent
Exceptions
Nothing.

◆ span() [7/10]

template<typename T , std::ptrdiff_t N = dynamic_extent>
template<typename Container >
constexpr fub::span< T, N >::span ( const Container &  container)
inlineconstexpr

Implicit conversion operator from a constant container.

Parameters
[in]containerA container which owns the contiguous memory. The container must outlive this span, otherwise the span is dangling.
Template Parameters
ContainerA container class which has the class member functions Container::data() and Container::size().
Precondition
extent <= container.size()
!is_span_v<Container>
Postcondition
data() == container.data()
size() == container.size() == extent
Exceptions
Nothing.

◆ span() [8/10]

template<typename T , std::ptrdiff_t N = dynamic_extent>
template<typename S , std::ptrdiff_t M>
constexpr fub::span< T, N >::span ( const span< S, M > &  s)
inlineconstexprnoexcept

Implicit conversion from other span types.

Template Parameters
Sthe element type of the other span.
Mthe static extents of the other span.
Precondition
s.size() == extent
std::is_convertible<S(*)[], T(*)[]>::value
Postcondition
data() == s.data()
size() == s.size() == extent.

◆ span() [9/10]

template<typename T , std::ptrdiff_t N = dynamic_extent>
template<typename S , typename = std::enable_if_t<std::is_convertible< typename span<S>::element_type (*)[], element_type (*)[]>::value>>
constexpr fub::span< T, N >::span ( const span< S > &  s)
inlineconstexpr

Constructs a span from a pointer and size pair.

This performs an assertion check in debug builds which will terminate the application if the specified size does not match the extent.

Parameters
[in]pa valid address pointing to the first element of the span.
[in]sizethe size such that [p, p + size) is a valid range.
Precondition
size == extent
Postcondition
data() == p
size() == size
Exceptions
Nothing.

◆ span() [10/10]

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr fub::span< T, N >::span ( const span< T, N > &  s)
constexprdefaultnoexcept

Defaulted copy constructor to trivially copy the class member variables.

Exceptions
Nothing.

Member Function Documentation

◆ begin()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr iterator fub::span< T, N >::begin ( ) const
inlineconstexprnoexcept

Returns an iterator pointing to the first element of the span.

Exceptions
Nothing.

◆ cbegin()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr const_iterator fub::span< T, N >::cbegin ( ) const
inlineconstexprnoexcept

Returns a const iterator pointing to the first element of the span.

Exceptions
Nothing.

◆ cend()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr const_iterator fub::span< T, N >::cend ( ) const
inlineconstexprnoexcept

Returns a const iterator pointing one after the last element of the span.

Exceptions
Nothing.

◆ crbegin()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr const_reverse_iterator fub::span< T, N >::crbegin ( ) const
inlineconstexprnoexcept

Returns a const reverse iterator pointing to the last element of the span.

Exceptions
Nothing.

◆ crend()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr const_reverse_iterator fub::span< T, N >::crend ( ) const
inlineconstexprnoexcept

Returns a const reverse iterator pointing to the first element of the span.

Exceptions
Nothing.

◆ data()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr pointer fub::span< T, N >::data ( ) const
inlineconstexprnoexcept

Returns the underlying pointer.

Exceptions
Nothing.

◆ empty()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr bool fub::span< T, N >::empty ( ) const
inlineconstexprnoexcept

Returns true if size() == 0.

Exceptions
Nothing.

◆ end()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr iterator fub::span< T, N >::end ( ) const
inlineconstexprnoexcept

Returns an iterator pointing one after the last element of the span.

Exceptions
Nothing.

◆ first() [1/2]

template<typename T , std::ptrdiff_t N = dynamic_extent>
template<ptrdiff_t Count, typename = std::enable_if_t<(0 <= Count && Count <= extent)>>
constexpr span<element_type, Count> fub::span< T, N >::first ( ) const
inlineconstexpr

Returns a span of the first Count-many elements of this span.

Template Parameters
CountSize of the returned subspan.
Precondition
0 <= Count && Count <= extent.
Exceptions
Nothing.

◆ first() [2/2]

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr span<element_type> fub::span< T, N >::first ( index_type  count) const
inlineconstexpr

Returns a span of the first count-many elements of this span.

Parameters
[in]countSize of the returned subspan.
Precondition
0 <= count && count <= extent.
Exceptions
Nothing.

◆ last() [1/2]

template<typename T , std::ptrdiff_t N = dynamic_extent>
template<ptrdiff_t Count, typename = std::enable_if_t<(0 <= Count && Count <= extent)>>
constexpr span<element_type, Count> fub::span< T, N >::last ( ) const
inlineconstexpr

Returns a span of the last Count-many elements of this span.

Template Parameters
CountSize of the returned subspan.
Precondition
0 <= Count && Count <= extent.
Exceptions
Nothing.

◆ last() [2/2]

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr span<element_type> fub::span< T, N >::last ( index_type  count) const
inlineconstexpr

Returns a span of the last count-many elements of this span.

Parameters
[in]countSize of the returned subspan.
Precondition
0 <= count && count <= extent.
Exceptions
Nothing.

◆ operator()()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr reference fub::span< T, N >::operator() ( index_type  n) const
inlineconstexpr

Accesses the n-th element of the spanned array.

Exceptions
Nothing.

◆ operator[]()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr reference fub::span< T, N >::operator[] ( index_type  n) const
inlineconstexpr

Accesses the n-th element of the spanned array.

Exceptions
Nothing.

◆ rbegin()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr reverse_iterator fub::span< T, N >::rbegin ( ) const
inlineconstexprnoexcept

Returns a reverse iterator pointing to the last element of the span.

Exceptions
Nothing.

◆ rend()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr reverse_iterator fub::span< T, N >::rend ( ) const
inlineconstexprnoexcept

Returns a reverse iterator pointing to the first element of the span.

Exceptions
Nothing.

◆ size()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr index_type fub::span< T, N >::size ( ) const
inlineconstexprnoexcept

Returns the number of elements in the span.

Exceptions
Nothing.

◆ size_bytes()

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr index_type fub::span< T, N >::size_bytes ( ) const
inlineconstexprnoexcept

Returns the number of bytes which are spanned by this span.

Exceptions
Nothing.

◆ subspan() [1/2]

template<typename T , std::ptrdiff_t N = dynamic_extent>
template<ptrdiff_t Offset, ptrdiff_t Count = dynamic_extent, typename = std::enable_if_t<(0 <= Offset && Offset <= extent)>, typename = std::enable_if_t<(Count == dynamic_extent || (0 <= Count && Count + Offset <= extent))>>
constexpr auto fub::span< T, N >::subspan ( ) const
inlineconstexpr

Returns a subspan viewing Count many elements from offset Offset.

Template Parameters
Offsetthe offset of the returned subspan.
CountSize of the returned subspan.
Precondition
0 <= Count && Count <= extent.
Exceptions
Nothing.

◆ subspan() [2/2]

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr span<element_type> fub::span< T, N >::subspan ( index_type  offset,
index_type  count = dynamic_extent 
) const
inlineconstexpr

Returns a subspan viewing count many elements from offset offset.

Parameters
offsetthe offset of the returned subspan.
countSize of the returned subspan.
Precondition
0 <= offset && offset <= extent.
count == dynamic_extent || 0 <= count && count + offset <= size().
Exceptions
Nothing.

Member Data Documentation

◆ extent

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr index_type fub::span< T, N >::extent
staticconstexpr

◆ pointer_

template<typename T , std::ptrdiff_t N = dynamic_extent>
pointer fub::span< T, N >::pointer_
private

Returns an iterator pointing to the first element of the span.

Exceptions
Nothing.

◆ sextent

template<typename T , std::ptrdiff_t N = dynamic_extent>
constexpr std::size_t fub::span< T, N >::sextent
staticconstexpr

The documentation for this class was generated from the following file: