ATLAS Offline Software
Public Types | Public Member Functions | Private Attributes | List of all members
CxxUtils::span< T > Class Template Reference

Simplified version of the C++20 std::span. More...

#include <span.h>

Collaboration diagram for CxxUtils::span< T >:

Public Types

using element_type = T
 Required typedefs. More...
 
using value_type = std::remove_cv_t< T >
 
using size_type = std::size_t
 
using difference_type = std::ptrdiff_t
 
using pointer = T *
 
using const_pointer = const T *
 
using reference = element_type &
 
using const_reference = const element_type &
 
using iterator = pointer
 
using const_iterator = const_pointer
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

 span ()
 
template<class U , typename = std::enable_if_t<valid_span_type_v<T, U> >>
 span (U *ptr, size_type sz)
 Constructor from start and length. More...
 
template<class U , typename = std::enable_if_t<valid_span_type_v<T, U> >>
 span (U *beg, U *end)
 Constructor from start and end. More...
 
 span (const span &)=default
 
spanoperator= (const span &)=default
 
template<class U , typename = std::enable_if_t<valid_span_type_v<T, U> >>
 span (const span< U > &other)
 Constructor from another span. More...
 
constexpr size_type size () const noexcept
 Return the size of the span. More...
 
constexpr size_type size_bytes () const noexcept
 Return the size of contents of the span, in bytes. More...
 
constexpr bool empty () const noexcept
 Test if the span is empty. More...
 
constexpr reference front () noexcept
 Return a reference to the first element in the span. More...
 
constexpr const_reference front () const noexcept
 Return a reference to the first element in the span. More...
 
constexpr reference back () noexcept
 Return a reference to the last element in the span. More...
 
constexpr const_reference back () const noexcept
 Return a reference to the last element in the span. More...
 
constexpr reference operator[] (size_type i) noexcept
 Return a reference to the i-th element in the span. More...
 
constexpr const_reference operator[] (size_type i) const noexcept
 Return a reference to the i-th element in the span. More...
 
constexpr reference at (size_type i)
 Return a reference to the i-th element in the span (bounds-checked). More...
 
constexpr const_reference at (size_type i) const
 Return a reference to the i-th element in the span (bounds-checked). More...
 
constexpr pointer data () noexcept
 Return a pointer to the start of the span. More...
 
constexpr const_pointer data () const noexcept
 Return a pointer to the start of the span. More...
 
constexpr iterator begin () noexcept
 Return a begin iterator. More...
 
constexpr const_iterator begin () const noexcept
 Return a begin iterator. More...
 
constexpr iterator end () noexcept
 Return an end iterator. More...
 
constexpr const_iterator end () const noexcept
 Return an end iterator. More...
 
constexpr reverse_iterator rbegin () noexcept
 Return a begin reverse iterator. More...
 
constexpr const_reverse_iterator rbegin () const noexcept
 Return a begin reverse iterator. More...
 
constexpr reverse_iterator rend () noexcept
 Return an end reverse iterator. More...
 
constexpr const_reverse_iterator rend () const noexcept
 Return an end reverse iterator. More...
 
constexpr span first (size_type n) noexcept
 Return a subspan from the start. More...
 
constexpr span< const T > first (size_type n) const noexcept
 Return a subspan from the start. More...
 
constexpr span last (size_type n) noexcept
 Return a subspan from the end. More...
 
constexpr span< const T > last (size_type n) const noexcept
 Return a subspan from the end. More...
 
constexpr span subspan (size_type offs, size_type n=dynamic_extent) noexcept
 Return a subspan. More...
 
constexpr span< const T > subspan (size_type offs, size_type n=dynamic_extent) const noexcept
 Return a subspan. More...
 

Private Attributes

T * m_ptr
 Pointer to the start of the span. More...
 
size_t m_size
 Number of elements in the span. More...
 

Detailed Description

template<class T>
class CxxUtils::span< T >

Simplified version of the C++20 std::span.

This class is meant to be very similar to the C++20 std::span class. There are however a few differences.

Contact the core sw group if any of these are a problem.

In addition:

Definition at line 63 of file span.h.

Member Typedef Documentation

◆ const_iterator

template<class T >
using CxxUtils::span< T >::const_iterator = const_pointer

Definition at line 79 of file span.h.

◆ const_pointer

template<class T >
using CxxUtils::span< T >::const_pointer = const T*

Definition at line 75 of file span.h.

◆ const_reference

template<class T >
using CxxUtils::span< T >::const_reference = const element_type&

Definition at line 77 of file span.h.

◆ const_reverse_iterator

template<class T >
using CxxUtils::span< T >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Definition at line 81 of file span.h.

◆ difference_type

template<class T >
using CxxUtils::span< T >::difference_type = std::ptrdiff_t

Definition at line 73 of file span.h.

◆ element_type

template<class T >
using CxxUtils::span< T >::element_type = T

Required typedefs.

Definition at line 70 of file span.h.

◆ iterator

template<class T >
using CxxUtils::span< T >::iterator = pointer

Definition at line 78 of file span.h.

◆ pointer

template<class T >
using CxxUtils::span< T >::pointer = T*

Definition at line 74 of file span.h.

◆ reference

template<class T >
using CxxUtils::span< T >::reference = element_type&

Definition at line 76 of file span.h.

◆ reverse_iterator

template<class T >
using CxxUtils::span< T >::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 80 of file span.h.

◆ size_type

template<class T >
using CxxUtils::span< T >::size_type = std::size_t

Definition at line 72 of file span.h.

◆ value_type

template<class T >
using CxxUtils::span< T >::value_type = std::remove_cv_t<T>

Definition at line 71 of file span.h.

Constructor & Destructor Documentation

◆ span() [1/5]

template<class T >
CxxUtils::span< T >::span ( )

◆ span() [2/5]

template<class T >
template<class U , typename = std::enable_if_t<valid_span_type_v<T, U> >>
CxxUtils::span< T >::span ( U *  ptr,
size_type  sz 
)

Constructor from start and length.

Parameters
ptrStart of the span.
szLength of the span.

◆ span() [3/5]

template<class T >
template<class U , typename = std::enable_if_t<valid_span_type_v<T, U> >>
CxxUtils::span< T >::span ( U *  beg,
U *  end 
)

Constructor from start and end.

Parameters
begStart of the span.
endOne past the end of the span.

◆ span() [4/5]

template<class T >
CxxUtils::span< T >::span ( const span< T > &  )
default

◆ span() [5/5]

template<class T >
template<class U , typename = std::enable_if_t<valid_span_type_v<T, U> >>
CxxUtils::span< T >::span ( const span< U > &  other)

Constructor from another span.

Parameters
otherSpan to copy from.

Member Function Documentation

◆ at() [1/2]

template<class T >
constexpr reference CxxUtils::span< T >::at ( size_type  i)
constexpr

Return a reference to the i-th element in the span (bounds-checked).

/

Parameters
iIndex of the element to return.

◆ at() [2/2]

template<class T >
constexpr const_reference CxxUtils::span< T >::at ( size_type  i) const
constexpr

Return a reference to the i-th element in the span (bounds-checked).

/

Parameters
iIndex of the element to return.

◆ back() [1/2]

template<class T >
constexpr const_reference CxxUtils::span< T >::back ( ) const
constexprnoexcept

Return a reference to the last element in the span.

◆ back() [2/2]

template<class T >
constexpr reference CxxUtils::span< T >::back ( )
constexprnoexcept

Return a reference to the last element in the span.

◆ begin() [1/2]

template<class T >
constexpr const_iterator CxxUtils::span< T >::begin ( ) const
constexprnoexcept

Return a begin iterator.

◆ begin() [2/2]

template<class T >
constexpr iterator CxxUtils::span< T >::begin ( )
constexprnoexcept

Return a begin iterator.

◆ data() [1/2]

template<class T >
constexpr const_pointer CxxUtils::span< T >::data ( ) const
constexprnoexcept

Return a pointer to the start of the span.

◆ data() [2/2]

template<class T >
constexpr pointer CxxUtils::span< T >::data ( )
constexprnoexcept

Return a pointer to the start of the span.

◆ empty()

template<class T >
constexpr bool CxxUtils::span< T >::empty ( ) const
constexprnoexcept

Test if the span is empty.

◆ end() [1/2]

template<class T >
constexpr const_iterator CxxUtils::span< T >::end ( ) const
constexprnoexcept

Return an end iterator.

◆ end() [2/2]

template<class T >
constexpr iterator CxxUtils::span< T >::end ( )
constexprnoexcept

Return an end iterator.

◆ first() [1/2]

template<class T >
constexpr span<const T> CxxUtils::span< T >::first ( size_type  n) const
constexprnoexcept

Return a subspan from the start.

Parameters
nNumber of elements in the subspan.

◆ first() [2/2]

template<class T >
constexpr span CxxUtils::span< T >::first ( size_type  n)
constexprnoexcept

Return a subspan from the start.

Parameters
nNumber of elements in the subspan.

◆ front() [1/2]

template<class T >
constexpr const_reference CxxUtils::span< T >::front ( ) const
constexprnoexcept

Return a reference to the first element in the span.

◆ front() [2/2]

template<class T >
constexpr reference CxxUtils::span< T >::front ( )
constexprnoexcept

Return a reference to the first element in the span.

◆ last() [1/2]

template<class T >
constexpr span<const T> CxxUtils::span< T >::last ( size_type  n) const
constexprnoexcept

Return a subspan from the end.

Parameters
nNumber of elements in the subspan.

◆ last() [2/2]

template<class T >
constexpr span CxxUtils::span< T >::last ( size_type  n)
constexprnoexcept

Return a subspan from the end.

Parameters
nNumber of elements in the subspan.

◆ operator=()

template<class T >
span& CxxUtils::span< T >::operator= ( const span< T > &  )
default

◆ operator[]() [1/2]

template<class T >
constexpr const_reference CxxUtils::span< T >::operator[] ( size_type  i) const
constexprnoexcept

Return a reference to the i-th element in the span.

Parameters
iIndex of the element to return.

◆ operator[]() [2/2]

template<class T >
constexpr reference CxxUtils::span< T >::operator[] ( size_type  i)
constexprnoexcept

Return a reference to the i-th element in the span.

Parameters
iIndex of the element to return.

◆ rbegin() [1/2]

template<class T >
constexpr const_reverse_iterator CxxUtils::span< T >::rbegin ( ) const
constexprnoexcept

Return a begin reverse iterator.

◆ rbegin() [2/2]

template<class T >
constexpr reverse_iterator CxxUtils::span< T >::rbegin ( )
constexprnoexcept

Return a begin reverse iterator.

◆ rend() [1/2]

template<class T >
constexpr const_reverse_iterator CxxUtils::span< T >::rend ( ) const
constexprnoexcept

Return an end reverse iterator.

◆ rend() [2/2]

template<class T >
constexpr reverse_iterator CxxUtils::span< T >::rend ( )
constexprnoexcept

Return an end reverse iterator.

◆ size()

template<class T >
constexpr size_type CxxUtils::span< T >::size ( ) const
constexprnoexcept

Return the size of the span.

◆ size_bytes()

template<class T >
constexpr size_type CxxUtils::span< T >::size_bytes ( ) const
constexprnoexcept

Return the size of contents of the span, in bytes.

◆ subspan() [1/2]

template<class T >
constexpr span<const T> CxxUtils::span< T >::subspan ( size_type  offs,
size_type  n = dynamic_extent 
) const
constexprnoexcept

Return a subspan.

Parameters
offsStarting element of the subspan.
nNumber of elements in the subspan. If defaulted, take all remaining elements.

◆ subspan() [2/2]

template<class T >
constexpr span CxxUtils::span< T >::subspan ( size_type  offs,
size_type  n = dynamic_extent 
)
constexprnoexcept

Return a subspan.

Parameters
offsStarting element of the subspan.
nNumber of elements in the subspan. If defaulted, take all remaining elements.

Member Data Documentation

◆ m_ptr

template<class T >
T* CxxUtils::span< T >::m_ptr
private

Pointer to the start of the span.

Definition at line 317 of file span.h.

◆ m_size

template<class T >
size_t CxxUtils::span< T >::m_size
private

Number of elements in the span.

Definition at line 320 of file span.h.


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