MIP_SDK  v4.0.0
MicroStrain Communications Library for embedded systems
Public Types | Public Member Functions | Static Public Attributes | List of all members
microstrain::ArrayView< T, Extent > Struct Template Reference

Represents a view over a contiguous array of objects, similar to std::span, and is implemented as a pointer and length. More...

#include <array_view.hpp>

Public Types

using element_type = T
 
using value_type = typename std::remove_cv< T >::type
 
using difference_type = ptrdiff_t
 
using pointer = T *
 
using reference = T &
 
using iterator = T *
 
using const_pointer = const T *
 
using const_reference = const T &
 
using const_iterator = const T *
 

Public Member Functions

constexpr ArrayView (pointer ptr)
 
constexpr pointer begin () const noexcept
 
constexpr pointer end () const noexcept
 
constexpr element_type front () const noexcept
 
constexpr element_type back () const noexcept
 
template<typename Index >
constexpr reference operator[] (Index idx) const noexcept
 
constexpr pointer data () const noexcept
 
constexpr size_t size () const noexcept
 
constexpr bool empty () const noexcept
 
constexpr ArrayView< T, DYNAMIC_EXTENTsubspan (size_t index, size_t length) const
 
constexpr ArrayView< T, DYNAMIC_EXTENTsubspan (size_t index) const
 
template<size_t Offset, size_t Count = DYNAMIC_EXTENT>
constexpr ArrayView< T, Count==DYNAMIC_EXTENT ? DYNAMIC_EXTENT :Extent-Count > subspan () const
 
constexpr ArrayView< T, DYNAMIC_EXTENTfirst (size_t count) const
 
template<size_t Count>
constexpr ArrayView< T, Count > first () const
 
constexpr ArrayView< T, DYNAMIC_EXTENTlast (size_t count) const
 
template<size_t Count>
constexpr ArrayView< T, Count > last () const
 
constexpr operator pointer () const
 

Static Public Attributes

static constexpr size_t extent = Extent
 

Detailed Description

template<class T, size_t Extent = DYNAMIC_EXTENT>
struct microstrain::ArrayView< T, Extent >

It can be used as a function parameter to accommodate std::vector, std::array, and C-style arrays in one function signature. It's acceptable to pass ArrayViews by value, which is equivalent to passing separate pointer and length parameters. The underlying data would not be copied.

Note that because ArrayView doesn't store the underlying data, the original buffer must remain intact while the view is in use.

Some functions provide both pointer+length and ArrayView versions, while others provide just the ArrayView version. To call an ArrayView-only function with a pointer and length, just put braces around the pointer and length arguments. This will create an ArrayView implicitly with no performance impact: theFunctionToCall( {pointer, length} );

To pass an ArrayView to a function taking separate pointer and length parameters, call .data() and .size() for each, like so: theFunctionToCall( view.data(), view.size() );

This class is intended to be mostly compatible and interchangeable with std::span, but certain features from span may be missing and additional ones may be added.

https://en.cppreference.com/w/cpp/container/span

Member Typedef Documentation

◆ element_type

template<class T , size_t Extent = DYNAMIC_EXTENT>
using microstrain::ArrayView< T, Extent >::element_type = T

◆ value_type

template<class T , size_t Extent = DYNAMIC_EXTENT>
using microstrain::ArrayView< T, Extent >::value_type = typename std::remove_cv<T>::type

◆ difference_type

template<class T , size_t Extent = DYNAMIC_EXTENT>
using microstrain::ArrayView< T, Extent >::difference_type = ptrdiff_t

◆ pointer

template<class T , size_t Extent = DYNAMIC_EXTENT>
using microstrain::ArrayView< T, Extent >::pointer = T*

◆ reference

template<class T , size_t Extent = DYNAMIC_EXTENT>
using microstrain::ArrayView< T, Extent >::reference = T&

◆ iterator

template<class T , size_t Extent = DYNAMIC_EXTENT>
using microstrain::ArrayView< T, Extent >::iterator = T*

◆ const_pointer

template<class T , size_t Extent = DYNAMIC_EXTENT>
using microstrain::ArrayView< T, Extent >::const_pointer = const T*

◆ const_reference

template<class T , size_t Extent = DYNAMIC_EXTENT>
using microstrain::ArrayView< T, Extent >::const_reference = const T&

◆ const_iterator

template<class T , size_t Extent = DYNAMIC_EXTENT>
using microstrain::ArrayView< T, Extent >::const_iterator = const T*

Constructor & Destructor Documentation

◆ ArrayView()

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr microstrain::ArrayView< T, Extent >::ArrayView ( pointer  ptr)
inlineexplicitconstexpr

Member Function Documentation

◆ begin()

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr pointer microstrain::ArrayView< T, Extent >::begin ( ) const
inlineconstexprnoexcept

◆ end()

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr pointer microstrain::ArrayView< T, Extent >::end ( ) const
inlineconstexprnoexcept

◆ front()

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr element_type microstrain::ArrayView< T, Extent >::front ( ) const
inlineconstexprnoexcept

◆ back()

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr element_type microstrain::ArrayView< T, Extent >::back ( ) const
inlineconstexprnoexcept

◆ operator[]()

template<class T , size_t Extent = DYNAMIC_EXTENT>
template<typename Index >
constexpr reference microstrain::ArrayView< T, Extent >::operator[] ( Index  idx) const
inlineconstexprnoexcept

◆ data()

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr pointer microstrain::ArrayView< T, Extent >::data ( ) const
inlineconstexprnoexcept

◆ size()

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr size_t microstrain::ArrayView< T, Extent >::size ( ) const
inlineconstexprnoexcept

◆ empty()

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr bool microstrain::ArrayView< T, Extent >::empty ( ) const
inlineconstexprnoexcept

◆ subspan() [1/3]

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr ArrayView<T, DYNAMIC_EXTENT> microstrain::ArrayView< T, Extent >::subspan ( size_t  index,
size_t  length 
) const
inlineconstexpr

◆ subspan() [2/3]

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr ArrayView<T, DYNAMIC_EXTENT> microstrain::ArrayView< T, Extent >::subspan ( size_t  index) const
inlineconstexpr

◆ subspan() [3/3]

template<class T , size_t Extent = DYNAMIC_EXTENT>
template<size_t Offset, size_t Count = DYNAMIC_EXTENT>
constexpr ArrayView<T, Count == DYNAMIC_EXTENT ? DYNAMIC_EXTENT : Extent-Count> microstrain::ArrayView< T, Extent >::subspan ( ) const
inlineconstexpr

◆ first() [1/2]

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr ArrayView<T, DYNAMIC_EXTENT> microstrain::ArrayView< T, Extent >::first ( size_t  count) const
inlineconstexpr

◆ first() [2/2]

template<class T , size_t Extent = DYNAMIC_EXTENT>
template<size_t Count>
constexpr ArrayView<T, Count> microstrain::ArrayView< T, Extent >::first ( ) const
inlineconstexpr

◆ last() [1/2]

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr ArrayView<T, DYNAMIC_EXTENT> microstrain::ArrayView< T, Extent >::last ( size_t  count) const
inlineconstexpr

◆ last() [2/2]

template<class T , size_t Extent = DYNAMIC_EXTENT>
template<size_t Count>
constexpr ArrayView<T, Count> microstrain::ArrayView< T, Extent >::last ( ) const
inlineconstexpr

◆ operator pointer()

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr microstrain::ArrayView< T, Extent >::operator pointer ( ) const
inlineconstexpr

Member Data Documentation

◆ extent

template<class T , size_t Extent = DYNAMIC_EXTENT>
constexpr size_t microstrain::ArrayView< T, Extent >::extent = Extent
staticconstexpr

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