rexlib 0.1.0
Device-agnostic array computing library for CryoEM and CryoET image processing, with a pluggable backend architecture
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
rexlib::span< T, Extent > Class Template Reference

Represents a non-owning area of contiguous memory. More...

#include <rexlib/core/span.hpp>

Public Types

using element_type = T
 
using value_type = typename std::remove_cv< element_type >::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 >
 

Public Member Functions

REXLIB_CONSTEXPR span (pointer ptr, size_type count)
 Construct from a pointer and size.
 
REXLIB_CONSTEXPR span (pointer first, pointer last)
 Construct from a pointer pair.
 
template<std::size_t Extent2>
REXLIB_CONSTEXPR span (const span< value_type, Extent2 > &other)
 Construct span from another span.
 
template<std::size_t Extent2>
REXLIB_CONSTEXPR span (const span< const value_type, Extent2 > &other)
 Construct span from another span.
 
 span (const span &other)=default
 
 span (span &&other)=default
 
span & operator= (const span &other)=default
 
span & operator= (span &&other)=default
 
REXLIB_CONSTEXPR size_type size () const noexcept
 Get the number of referenced objects.
 
REXLIB_CONSTEXPR size_type size_bytes () const noexcept
 Get the size in bytes of the referenced objects.
 
REXLIB_NODISCARD REXLIB_CONSTEXPR bool empty () const noexcept
 Check if no objects are references.
 
REXLIB_CONSTEXPR reference operator[] (size_type idx) const noexcept
 Obtain a reference to an object by its index.
 
REXLIB_CONSTEXPR reference front () const noexcept
 Obtain a reference to the first object.
 
REXLIB_CONSTEXPR reference back () const noexcept
 Obtain a reference to the last object.
 
REXLIB_CONSTEXPR pointer data () const noexcept
 Get a pointer to the referenced data.
 
REXLIB_CONSTEXPR iterator begin () const noexcept
 Get an iterator to the first item.
 
REXLIB_CONSTEXPR iterator end () const noexcept
 Get an iterator to the past-the-end item.
 
REXLIB_CONSTEXPR reverse_iterator rbegin () const noexcept
 Get a reverse iterator to the last item.
 
REXLIB_CONSTEXPR reverse_iterator rend () const noexcept
 Get a reverse iterator to the before-first item.
 

Static Public Attributes

static constexpr size_type extent = Extent
 

Detailed Description

template<typename T, std::size_t Extent = dynamic_extent>
class rexlib::span< T, Extent >

Represents a non-owning area of contiguous memory.

Provides a pre C++20 implementation of std::span.

Template Parameters
TType of the elements.
ExtentSize of the area. Use dynamic_extent dynamic assignation.

Constructor & Destructor Documentation

◆ span() [1/4]

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR rexlib::span< T, Extent >::span ( pointer  ptr,
size_type  count 
)

Construct from a pointer and size.

Parameters
ptrPointer to the data.
countNumber of elements.

◆ span() [2/4]

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR rexlib::span< T, Extent >::span ( pointer  first,
pointer  last 
)

Construct from a pointer pair.

Parameters
firstPointer to the first element.
lastPointer to the past-the-end element.

◆ span() [3/4]

template<typename T , std::size_t Extent = dynamic_extent>
template<std::size_t Extent2>
REXLIB_CONSTEXPR rexlib::span< T, Extent >::span ( const span< value_type, Extent2 > &  other)

Construct span from another span.

Template Parameters
Extent2The extent of the other span. Must be compatible with the current extent.
Parameters
otherThe other span.

◆ span() [4/4]

template<typename T , std::size_t Extent = dynamic_extent>
template<std::size_t Extent2>
REXLIB_CONSTEXPR rexlib::span< T, Extent >::span ( const span< const value_type, Extent2 > &  other)

Construct span from another span.

Template Parameters
Extent2The extent of the other span. Must be compatible with the current extent.
Parameters
otherThe other span.

Member Function Documentation

◆ back()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR reference rexlib::span< T, Extent >::back ( ) const
noexcept

Obtain a reference to the last object.

Returns
reference Reference to the last object.
Note
No emptiness check is performed. Calling this method when empty() == true leads to undefined behavior.

◆ begin()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR iterator rexlib::span< T, Extent >::begin ( ) const
noexcept

Get an iterator to the first item.

Returns
iterator Iterator to the first item.

◆ data()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR pointer rexlib::span< T, Extent >::data ( ) const
noexcept

Get a pointer to the referenced data.

Returns
pointer Pointer to the referenced data.

◆ empty()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_NODISCARD REXLIB_CONSTEXPR bool rexlib::span< T, Extent >::empty ( ) const
noexcept

Check if no objects are references.

Returns
true If 0 objects are referenced.
false If 1 or more objects are referenced.

◆ end()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR iterator rexlib::span< T, Extent >::end ( ) const
noexcept

Get an iterator to the past-the-end item.

Returns
iterator Iterator to the past the end item.

◆ front()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR reference rexlib::span< T, Extent >::front ( ) const
noexcept

Obtain a reference to the first object.

Returns
reference Reference to the first object.
Note
No emptiness check is performed. Calling this method when empty() == true leads to undefined behavior.

◆ operator[]()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR reference rexlib::span< T, Extent >::operator[] ( size_type  idx) const
noexcept

Obtain a reference to an object by its index.

Parameters
idxThe index of the object. Must be in [0...size())
Returns
reference The reference to the requested object.
Note
No boundary checks are performed. Using an index that is greater or equal to the size leads to undefined behavior.

◆ rbegin()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR reverse_iterator rexlib::span< T, Extent >::rbegin ( ) const
noexcept

Get a reverse iterator to the last item.

Returns
reverse_iterator Reverse iterator to the last item.

◆ rend()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR reverse_iterator rexlib::span< T, Extent >::rend ( ) const
noexcept

Get a reverse iterator to the before-first item.

Returns
reverse_iterator Reverse iterator to the before-first item.

◆ size()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR size_type rexlib::span< T, Extent >::size ( ) const
noexcept

Get the number of referenced objects.

Returns
size_type Number of objects.

◆ size_bytes()

template<typename T , std::size_t Extent = dynamic_extent>
REXLIB_CONSTEXPR size_type rexlib::span< T, Extent >::size_bytes ( ) const
noexcept

Get the size in bytes of the referenced objects.

Returns
size_type Number of bytes.

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