GEOSX
Public Types | Public Member Functions | List of all members
geos::Span< T > Class Template Reference

Lightweight non-owning wrapper over a contiguous range of elements. More...

#include <Span.hpp>

Public Types

using element_type = T
 Type of range element.
 
using value_type = std::remove_cv_t< T >
 Type of underlying value.
 
using size_type = std::size_t
 Type used for indexing the range.
 
using difference_type = std::ptrdiff_t
 Type used for indexing the range.
 

Public Member Functions

constexpr Span () noexcept=default
 Construct an empty span.
 
 Span (T *const ptr, size_type const size) noexcept
 Construct a span from pointer and size. More...
 
template<typename ITER >
constexpr Span (ITER const begin, ITER const end) noexcept
 Construct a span from pair of iterators. More...
 
template<int N>
constexpr Span (T(&arr)[N]) noexcept
 Construct a span from a c-array. More...
 
template<typename R , typename std::enable_if_t< traits::is_range_like< R > > * = nullptr>
constexpr Span (R const &range)
 Construct a span from a range-like object (anything that has begin() and end()). More...
 
constexpr size_type size () const noexcept
 
constexpr size_type size_bytes () const noexcept
 
constexpr bool empty () const noexcept
 
constexpr T * data () const noexcept
 
constexpr T * begin () const noexcept
 
constexpr T * end () const noexcept
 
constexpr std::reverse_iterator< T * > rbegin () const noexcept
 
constexpr std::reverse_iterator< T * > rend () const noexcept
 
T & front () const
 
T & back () const
 
T & operator[] (size_type const i) const
 
Span< element_typefirst (size_type const count) const
 
Span< element_typelast (size_type const count) const
 
Span< element_typesubspan (size_type const offset, size_type const count) const
 

Detailed Description

template<typename T>
class geos::Span< T >

Lightweight non-owning wrapper over a contiguous range of elements.

Template Parameters
Ttype of range element

This is a simplified version of C++17's std::span<> that doesn't support compile-time extents.

Definition at line 40 of file Span.hpp.

Constructor & Destructor Documentation

◆ Span() [1/4]

template<typename T >
geos::Span< T >::Span ( T *const  ptr,
size_type const  size 
)
inlinenoexcept

Construct a span from pointer and size.

Parameters
ptrpointer to beginning of contiguous range
sizenumber of elements

Definition at line 66 of file Span.hpp.

◆ Span() [2/4]

template<typename T >
template<typename ITER >
constexpr geos::Span< T >::Span ( ITER const  begin,
ITER const  end 
)
inlineconstexprnoexcept

Construct a span from pair of iterators.

Template Parameters
ITERtype of iterators
Parameters
beginiterator to start of the range
enditerator to end of the range

Definition at line 78 of file Span.hpp.

◆ Span() [3/4]

template<typename T >
template<int N>
constexpr geos::Span< T >::Span ( T(&)  arr[N])
inlineconstexprnoexcept

Construct a span from a c-array.

Template Parameters
Ncompile-time size of array
Parameters
arrreference to array

Definition at line 88 of file Span.hpp.

◆ Span() [4/4]

template<typename T >
template<typename R , typename std::enable_if_t< traits::is_range_like< R > > * = nullptr>
constexpr geos::Span< T >::Span ( R const &  range)
inlineconstexpr

Construct a span from a range-like object (anything that has begin() and end()).

Template Parameters
Rthe range type
Parameters
rangereference to the range
Note
The user must guarantee that the range is contiguous in memory.

Definition at line 99 of file Span.hpp.

Member Function Documentation

◆ back()

template<typename T >
T& geos::Span< T >::back ( ) const
inline
Returns
reference to the last element
Precondition
!empty()

Definition at line 181 of file Span.hpp.

◆ begin()

template<typename T >
constexpr T* geos::Span< T >::begin ( ) const
inlineconstexprnoexcept
Returns
iterator to start of the range

Definition at line 138 of file Span.hpp.

◆ data()

template<typename T >
constexpr T* geos::Span< T >::data ( ) const
inlineconstexprnoexcept
Returns
raw pointer to the data

Definition at line 130 of file Span.hpp.

◆ empty()

template<typename T >
constexpr bool geos::Span< T >::empty ( ) const
inlineconstexprnoexcept
Returns
true iff range is empty

Definition at line 122 of file Span.hpp.

◆ end()

template<typename T >
constexpr T* geos::Span< T >::end ( ) const
inlineconstexprnoexcept
Returns
iterator past-the-end of the range

Definition at line 146 of file Span.hpp.

◆ first()

template<typename T >
Span< element_type > geos::Span< T >::first ( size_type const  count) const
inline
Returns
a new span of count starting elements
Parameters
count

Definition at line 202 of file Span.hpp.

◆ front()

template<typename T >
T& geos::Span< T >::front ( ) const
inline
Returns
reference to the first element
Precondition
!empty()

Definition at line 171 of file Span.hpp.

◆ last()

template<typename T >
Span< element_type > geos::Span< T >::last ( size_type const  count) const
inline
Returns
a new span of count trailing elements
Parameters
countnumber of elements

Definition at line 212 of file Span.hpp.

◆ operator[]()

template<typename T >
T& geos::Span< T >::operator[] ( size_type const  i) const
inline
Returns
reference to i-th element
Parameters
ielement index
Precondition
0 <= i < size()

Definition at line 192 of file Span.hpp.

◆ rbegin()

template<typename T >
constexpr std::reverse_iterator< T * > geos::Span< T >::rbegin ( ) const
inlineconstexprnoexcept
Returns
reverse iterator to start or the range

Definition at line 154 of file Span.hpp.

◆ rend()

template<typename T >
constexpr std::reverse_iterator< T * > geos::Span< T >::rend ( ) const
inlineconstexprnoexcept
Returns
reverse iterator to end of the range

Definition at line 162 of file Span.hpp.

◆ size()

template<typename T >
constexpr size_type geos::Span< T >::size ( ) const
inlineconstexprnoexcept
Returns
size of the range

Definition at line 106 of file Span.hpp.

◆ size_bytes()

template<typename T >
constexpr size_type geos::Span< T >::size_bytes ( ) const
inlineconstexprnoexcept
Returns
size of the range in bytes

Definition at line 114 of file Span.hpp.

◆ subspan()

template<typename T >
Span< element_type > geos::Span< T >::subspan ( size_type const  offset,
size_type const  count 
) const
inline
Returns
a new span of count elements starting at offset
Parameters
offsetstarting index
countnumber of elements

Definition at line 223 of file Span.hpp.


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