ATLAS Offline Software
Loading...
Searching...
No Matches
CxxUtils::span< T > Class Template Reference

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

#include <span.h>

Inheritance diagram for CxxUtils::span< T >:
Collaboration diagram for CxxUtils::span< T >:

Public Types

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

Private Attributes

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

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.

  • The option for a fixed-length span is not implemented; hence, there is no second template argument.
  • Constructors from arrays / std::array are not implemented.
  • The external member functions as_bytes / as_writable_bytes and not all deduction guides are implemented.

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

In addition:

  • Accessor methods are split into const / non-const versions. This is required to avoid warnings from the thread-safety checker, but be careful of potential incompatibilies with std::span. Again, contact the core sw group if this is an issue.

Definition at line 59 of file span.h.

Member Typedef Documentation

◆ const_iterator

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

Definition at line 73 of file span.h.

◆ const_pointer

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

Definition at line 69 of file span.h.

◆ const_reference

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

Definition at line 71 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 75 of file span.h.

◆ difference_type

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

Definition at line 67 of file span.h.

◆ element_type

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

Required typedefs.

Definition at line 64 of file span.h.

◆ iterator

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

Definition at line 72 of file span.h.

◆ pointer

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

Definition at line 68 of file span.h.

◆ reference

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

Definition at line 70 of file span.h.

◆ reverse_iterator

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

Definition at line 74 of file span.h.

◆ size_type

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

Definition at line 66 of file span.h.

◆ value_type

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

Definition at line 65 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>
requires (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>
requires (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>
requires (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>
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>
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>
const_reference CxxUtils::span< T >::back ( ) const
constexprnoexcept

Return a reference to the last element in the span.

◆ back() [2/2]

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

Return a reference to the last element in the span.

◆ begin() [1/2]

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

Return a begin iterator.

◆ begin() [2/2]

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

Return a begin iterator.

◆ data() [1/2]

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

Return a pointer to the start of the span.

◆ data() [2/2]

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

Return a pointer to the start of the span.

◆ empty()

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

Test if the span is empty.

◆ end() [1/2]

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

Return an end iterator.

◆ end() [2/2]

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

Return an end iterator.

◆ first() [1/2]

template<class T>
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>
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>
const_reference CxxUtils::span< T >::front ( ) const
constexprnoexcept

Return a reference to the first element in the span.

◆ front() [2/2]

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

Return a reference to the first element in the span.

◆ last() [1/2]

template<class T>
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>
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>
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>
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>
const_reverse_iterator CxxUtils::span< T >::rbegin ( ) const
constexprnoexcept

Return a begin reverse iterator.

◆ rbegin() [2/2]

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

Return a begin reverse iterator.

◆ rend() [1/2]

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

Return an end reverse iterator.

◆ rend() [2/2]

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

Return an end reverse iterator.

◆ size()

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

Return the size of the span.

◆ size_bytes()

template<class T>
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>
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>
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 299 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 302 of file span.h.


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