preCICE v3.1.2
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Private Types | Private Attributes | List of all members
precice::span< ElementType, Extent > Class Template Reference

A C++ 11 implementation of the non-owning C++20 std::span type. More...

#include <span.hpp>

Collaboration diagram for precice::span< ElementType, Extent >:
[legend]

Public Types

using element_type = ElementType
 
using value_type = typename std::remove_cv<ElementType>::type
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using pointer = element_type*
 
using const_pointer = const element_type*
 
using reference = element_type&
 
using const_reference = const element_type&
 
using iterator = pointer
 
using reverse_iterator = std::reverse_iterator<iterator>
 
template<std::size_t Offset, std::size_t Count = dynamic_extent>
using subspan_return_t
 

Public Member Functions

template<std::size_t E = Extent, typename std::enable_if<(E==dynamic_extent||E<=0), int >::type = 0>
constexpr span () noexcept
 
PRECICE_SPAN_CONSTEXPR11 span (pointer ptr, size_type count)
 
PRECICE_SPAN_CONSTEXPR11 span (pointer first_elem, pointer last_elem)
 
template<std::size_t N, std::size_t E = Extent, typename std::enable_if<(E==dynamic_extent||N==E) &&detail::is_container_element_type_compatible< element_type(&)[N], ElementType >::value, int >::type = 0>
constexpr span (element_type(&arr)[N]) noexcept
 
template<typename T , std::size_t N, std::size_t E = Extent, typename std::enable_if<(E==dynamic_extent||N==E) &&detail::is_container_element_type_compatible< std::array< T, N > &, ElementType >::value, int >::type = 0>
PRECICE_SPAN_ARRAY_CONSTEXPR span (std::array< T, N > &arr) noexcept
 
template<typename T , std::size_t N, std::size_t E = Extent, typename std::enable_if<(E==dynamic_extent||N==E) &&detail::is_container_element_type_compatible< const std::array< T, N > &, ElementType >::value, int >::type = 0>
PRECICE_SPAN_ARRAY_CONSTEXPR span (const std::array< T, N > &arr) noexcept
 
template<typename Container , std::size_t E = Extent, typename std::enable_if< E==dynamic_extent &&detail::is_container< Container >::value &&detail::is_container_element_type_compatible< Container &, ElementType >::value, int >::type = 0>
constexpr span (Container &cont)
 
template<typename Container , std::size_t E = Extent, typename std::enable_if< E==dynamic_extent &&detail::is_container< Container >::value &&detail::is_container_element_type_compatible< const Container &, ElementType >::value, int >::type = 0>
constexpr span (const Container &cont)
 
constexpr span (const span &other) noexcept=default
 
template<typename OtherElementType , std::size_t OtherExtent, typename std::enable_if<(Extent==dynamic_extent||OtherExtent==dynamic_extent||Extent==OtherExtent) &&std::is_convertible< OtherElementType(*)[], ElementType(*)[]>::value, int >::type = 0>
constexpr span (const span< OtherElementType, OtherExtent > &other) noexcept
 
 ~span () noexcept=default
 
PRECICE_SPAN_CONSTEXPR_ASSIGN spanoperator= (const span &other) noexcept=default
 
template<typename T , std::size_t E = Extent, typename std::enable_if< E==dynamic_extent &&(std::is_same< T, const char * >::value||std::is_same< T, char * >::value), int >::type = 0>
 span (T cstring)
 
template<std::size_t Count>
PRECICE_SPAN_CONSTEXPR11 span< element_type, Count > first () const
 
template<std::size_t Count>
PRECICE_SPAN_CONSTEXPR11 span< element_type, Count > last () const
 
template<std::size_t Offset, std::size_t Count = dynamic_extent>
PRECICE_SPAN_CONSTEXPR11 subspan_return_t< Offset, Count > subspan () const
 
PRECICE_SPAN_CONSTEXPR11 span< element_type, dynamic_extentfirst (size_type count) const
 
PRECICE_SPAN_CONSTEXPR11 span< element_type, dynamic_extentlast (size_type count) const
 
PRECICE_SPAN_CONSTEXPR11 span< element_type, dynamic_extentsubspan (size_type offset, size_type count=dynamic_extent) const
 
constexpr size_type size () const noexcept
 
constexpr size_type size_bytes () const noexcept
 
PRECICE_SPAN_NODISCARD constexpr bool empty () const noexcept
 
PRECICE_SPAN_CONSTEXPR11 reference operator[] (size_type idx) const
 
PRECICE_SPAN_CONSTEXPR11 reference front () const
 
PRECICE_SPAN_CONSTEXPR11 reference back () const
 
constexpr pointer data () const noexcept
 
constexpr iterator begin () const noexcept
 
constexpr iterator end () const noexcept
 
PRECICE_SPAN_ARRAY_CONSTEXPR reverse_iterator rbegin () const noexcept
 
PRECICE_SPAN_ARRAY_CONSTEXPR reverse_iterator rend () const noexcept
 

Static Public Attributes

static constexpr size_type extent = Extent
 

Private Types

using storage_type = detail::span_storage<ElementType, Extent>
 

Private Attributes

storage_type storage_ {}
 

Detailed Description

template<typename ElementType, std::size_t Extent>
class precice::span< ElementType, Extent >

A C++ 11 implementation of the non-owning C++20 std::span type.

A span represents a non-owning view into a contiguous block of memory of a known size. This view can be mutable or const, depending on the type.

A simple mental model is an object that holds a pointer and size, so it knows how many elements it is allowed to access after the initial pointer. You can imagine a span<double> to look like this:

class span {
double* begin;
size_t size;
}
A C++ 11 implementation of the non-owning C++20 std::span type.
Definition span.hpp:284
constexpr iterator begin() const noexcept
Definition span.hpp:503
constexpr size_type size() const noexcept
Definition span.hpp:469

This type can also be read-only aka const. You can imagine a span<const double> to look like this:

class span {
double const* begin;
size_t size;
}

It can be constructed from:

Note
This version contains an additional constructor for const char *-style C strings, allowing the span to mimic C++17 std::string_view.

Definition at line 284 of file span.hpp.

Member Typedef Documentation

◆ const_pointer

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::const_pointer = const element_type*

Definition at line 303 of file span.hpp.

◆ const_reference

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::const_reference = const element_type&

Definition at line 305 of file span.hpp.

◆ difference_type

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::difference_type = std::ptrdiff_t

Definition at line 301 of file span.hpp.

◆ element_type

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::element_type = ElementType

Definition at line 298 of file span.hpp.

◆ iterator

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::iterator = pointer

Definition at line 306 of file span.hpp.

◆ pointer

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::pointer = element_type*

Definition at line 302 of file span.hpp.

◆ reference

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::reference = element_type&

Definition at line 304 of file span.hpp.

◆ reverse_iterator

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 307 of file span.hpp.

◆ size_type

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::size_type = std::size_t

Definition at line 300 of file span.hpp.

◆ storage_type

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::storage_type = detail::span_storage<ElementType, Extent>
private

Definition at line 294 of file span.hpp.

◆ subspan_return_t

template<typename ElementType , std::size_t Extent>
template<std::size_t Offset, std::size_t Count = dynamic_extent>
using precice::span< ElementType, Extent >::subspan_return_t
Initial value:
span<ElementType, Count != dynamic_extent
? Count
: (Extent != dynamic_extent ? Extent - Offset
constexpr span() noexcept
Definition span.hpp:315
PRECICE_SPAN_INLINE_VAR constexpr std::size_t dynamic_extent
Definition span.hpp:144

Definition at line 430 of file span.hpp.

◆ value_type

template<typename ElementType , std::size_t Extent>
using precice::span< ElementType, Extent >::value_type = typename std::remove_cv<ElementType>::type

Definition at line 299 of file span.hpp.

Constructor & Destructor Documentation

◆ span() [1/11]

template<typename ElementType , std::size_t Extent>
template<std::size_t E = Extent, typename std::enable_if<(E==dynamic_extent||E<=0), int >::type = 0>
constexpr precice::span< ElementType, Extent >::span ( )
inlineconstexprnoexcept

Definition at line 315 of file span.hpp.

◆ span() [2/11]

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_CONSTEXPR11 precice::span< ElementType, Extent >::span ( pointer ptr,
size_type count )
inline

Definition at line 318 of file span.hpp.

◆ span() [3/11]

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_CONSTEXPR11 precice::span< ElementType, Extent >::span ( pointer first_elem,
pointer last_elem )
inline

Definition at line 324 of file span.hpp.

◆ span() [4/11]

template<typename ElementType , std::size_t Extent>
template<std::size_t N, std::size_t E = Extent, typename std::enable_if<(E==dynamic_extent||N==E) &&detail::is_container_element_type_compatible< element_type(&)[N], ElementType >::value, int >::type = 0>
constexpr precice::span< ElementType, Extent >::span ( element_type(&) arr[N])
inlineconstexprnoexcept

Definition at line 338 of file span.hpp.

◆ span() [5/11]

template<typename ElementType , std::size_t Extent>
template<typename T , std::size_t N, std::size_t E = Extent, typename std::enable_if<(E==dynamic_extent||N==E) &&detail::is_container_element_type_compatible< std::array< T, N > &, ElementType >::value, int >::type = 0>
PRECICE_SPAN_ARRAY_CONSTEXPR precice::span< ElementType, Extent >::span ( std::array< T, N > & arr)
inlinenoexcept

Definition at line 347 of file span.hpp.

◆ span() [6/11]

template<typename ElementType , std::size_t Extent>
template<typename T , std::size_t N, std::size_t E = Extent, typename std::enable_if<(E==dynamic_extent||N==E) &&detail::is_container_element_type_compatible< const std::array< T, N > &, ElementType >::value, int >::type = 0>
PRECICE_SPAN_ARRAY_CONSTEXPR precice::span< ElementType, Extent >::span ( const std::array< T, N > & arr)
inlinenoexcept

Definition at line 357 of file span.hpp.

◆ span() [7/11]

template<typename ElementType , std::size_t Extent>
template<typename Container , std::size_t E = Extent, typename std::enable_if< E==dynamic_extent &&detail::is_container< Container >::value &&detail::is_container_element_type_compatible< Container &, ElementType >::value, int >::type = 0>
constexpr precice::span< ElementType, Extent >::span ( Container & cont)
inlineconstexpr

Definition at line 368 of file span.hpp.

◆ span() [8/11]

template<typename ElementType , std::size_t Extent>
template<typename Container , std::size_t E = Extent, typename std::enable_if< E==dynamic_extent &&detail::is_container< Container >::value &&detail::is_container_element_type_compatible< const Container &, ElementType >::value, int >::type = 0>
constexpr precice::span< ElementType, Extent >::span ( const Container & cont)
inlineconstexpr

Definition at line 379 of file span.hpp.

◆ span() [9/11]

template<typename ElementType , std::size_t Extent>
constexpr precice::span< ElementType, Extent >::span ( const span< ElementType, Extent > & other)
constexprdefaultnoexcept

◆ span() [10/11]

template<typename ElementType , std::size_t Extent>
template<typename OtherElementType , std::size_t OtherExtent, typename std::enable_if<(Extent==dynamic_extent||OtherExtent==dynamic_extent||Extent==OtherExtent) &&std::is_convertible< OtherElementType(*)[], ElementType(*)[]>::value, int >::type = 0>
constexpr precice::span< ElementType, Extent >::span ( const span< OtherElementType, OtherExtent > & other)
inlineconstexprnoexcept

Definition at line 392 of file span.hpp.

◆ ~span()

template<typename ElementType , std::size_t Extent>
precice::span< ElementType, Extent >::~span ( )
defaultnoexcept

◆ span() [11/11]

template<typename ElementType , std::size_t Extent>
template<typename T , std::size_t E = Extent, typename std::enable_if< E==dynamic_extent &&(std::is_same< T, const char * >::value||std::is_same< T, char * >::value), int >::type = 0>
precice::span< ElementType, Extent >::span ( T cstring)
inline

Definition at line 408 of file span.hpp.

Member Function Documentation

◆ back()

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_CONSTEXPR11 reference precice::span< ElementType, Extent >::back ( ) const
inline

Definition at line 494 of file span.hpp.

Here is the call graph for this function:

◆ begin()

template<typename ElementType , std::size_t Extent>
constexpr iterator precice::span< ElementType, Extent >::begin ( ) const
inlineconstexprnoexcept

Definition at line 503 of file span.hpp.

Here is the call graph for this function:

◆ data()

template<typename ElementType , std::size_t Extent>
constexpr pointer precice::span< ElementType, Extent >::data ( ) const
inlineconstexprnoexcept

Definition at line 500 of file span.hpp.

◆ empty()

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_NODISCARD constexpr bool precice::span< ElementType, Extent >::empty ( ) const
inlineconstexprnoexcept

Definition at line 476 of file span.hpp.

Here is the call graph for this function:

◆ end()

template<typename ElementType , std::size_t Extent>
constexpr iterator precice::span< ElementType, Extent >::end ( ) const
inlineconstexprnoexcept

Definition at line 505 of file span.hpp.

Here is the call graph for this function:

◆ first() [1/2]

template<typename ElementType , std::size_t Extent>
template<std::size_t Count>
PRECICE_SPAN_CONSTEXPR11 span< element_type, Count > precice::span< ElementType, Extent >::first ( ) const
inline

Definition at line 416 of file span.hpp.

Here is the call graph for this function:

◆ first() [2/2]

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_CONSTEXPR11 span< element_type, dynamic_extent > precice::span< ElementType, Extent >::first ( size_type count) const
inline

Definition at line 446 of file span.hpp.

Here is the call graph for this function:

◆ front()

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_CONSTEXPR11 reference precice::span< ElementType, Extent >::front ( ) const
inline

Definition at line 488 of file span.hpp.

Here is the call graph for this function:

◆ last() [1/2]

template<typename ElementType , std::size_t Extent>
template<std::size_t Count>
PRECICE_SPAN_CONSTEXPR11 span< element_type, Count > precice::span< ElementType, Extent >::last ( ) const
inline

Definition at line 423 of file span.hpp.

Here is the call graph for this function:

◆ last() [2/2]

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_CONSTEXPR11 span< element_type, dynamic_extent > precice::span< ElementType, Extent >::last ( size_type count) const
inline

Definition at line 453 of file span.hpp.

Here is the call graph for this function:

◆ operator=()

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_CONSTEXPR_ASSIGN span & precice::span< ElementType, Extent >::operator= ( const span< ElementType, Extent > & other)
defaultnoexcept

◆ operator[]()

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_CONSTEXPR11 reference precice::span< ElementType, Extent >::operator[] ( size_type idx) const
inline

Definition at line 482 of file span.hpp.

Here is the call graph for this function:

◆ rbegin()

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_ARRAY_CONSTEXPR reverse_iterator precice::span< ElementType, Extent >::rbegin ( ) const
inlinenoexcept

Definition at line 507 of file span.hpp.

Here is the call graph for this function:

◆ rend()

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_ARRAY_CONSTEXPR reverse_iterator precice::span< ElementType, Extent >::rend ( ) const
inlinenoexcept

Definition at line 512 of file span.hpp.

Here is the call graph for this function:

◆ size()

template<typename ElementType , std::size_t Extent>
constexpr size_type precice::span< ElementType, Extent >::size ( ) const
inlineconstexprnoexcept

Definition at line 469 of file span.hpp.

◆ size_bytes()

template<typename ElementType , std::size_t Extent>
constexpr size_type precice::span< ElementType, Extent >::size_bytes ( ) const
inlineconstexprnoexcept

Definition at line 471 of file span.hpp.

Here is the call graph for this function:

◆ subspan() [1/2]

template<typename ElementType , std::size_t Extent>
template<std::size_t Offset, std::size_t Count = dynamic_extent>
PRECICE_SPAN_CONSTEXPR11 subspan_return_t< Offset, Count > precice::span< ElementType, Extent >::subspan ( ) const
inline

Definition at line 437 of file span.hpp.

Here is the call graph for this function:

◆ subspan() [2/2]

template<typename ElementType , std::size_t Extent>
PRECICE_SPAN_CONSTEXPR11 span< element_type, dynamic_extent > precice::span< ElementType, Extent >::subspan ( size_type offset,
size_type count = dynamic_extent ) const
inline

Definition at line 460 of file span.hpp.

Here is the call graph for this function:

Member Data Documentation

◆ extent

template<typename ElementType , std::size_t Extent>
constexpr size_type precice::span< ElementType, Extent >::extent = Extent
staticconstexpr

Definition at line 309 of file span.hpp.

◆ storage_

template<typename ElementType , std::size_t Extent>
storage_type precice::span< ElementType, Extent >::storage_ {}
private

Definition at line 518 of file span.hpp.


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