Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions
ArrayView< T, Size > Struct Template Reference

Immutable view to an array. More...

#include <ArrayView.h>

Public Member Functions

 ArrayView ()
 Construct a view to an empty array. More...
 
 ArrayView (T *array_ptr, size_t array_size)
 Construct an array view from a pointer to a buffer. More...
 
 ArrayView (T(&elements)[Size])
 Construct an array view from the reference to an array. More...
 
size_t size () const
 Return the size of the array viewed. More...
 
T & operator[] (size_t index)
 Access to a mutable element of the array. More...
 
const T & operator[] (size_t index) const
 Access to an immutable element of the array. More...
 
T * data ()
 Get the raw pointer to the array. More...
 
const T * data () const
 Get the raw const pointer to the array. More...
 

Detailed Description

template<typename T, ptrdiff_t Size = -1>
struct ble::ArrayView< T, Size >

Immutable view to an array.

Array views encapsulate the pointer to an array and its size into a single object or type; however, it does not manage the lifetime of the array viewed. You can use instances of ArrayView to replace the traditional pair of pointer and size arguments in function calls.

You can use the size member function to query the number of elements present in the array, and overloads of the subscript operator allow code using this object to access to the content of the array viewed.

Note
You can create ArrayView instances with the help of the function template make_ArrayView() and make_const_ArrayView().
ArrayView<T, Size> objects can be implicitly converted to ArrayView<T> objects where required.
Template Parameters
Ttype of objects held by the array.
SizeThe size of the array viewed. The default value ARRAY_VIEW_DYNAMIC_SIZE is special as it allows construction of ArrayView objects of any size (set at runtime).

Definition at line 70 of file ArrayView.h.

Constructor & Destructor Documentation

ArrayView ( )

Construct a view to an empty array.

Postcondition
a call to size() will return 0, and data() will return NULL.

Definition at line 79 of file ArrayView.h.

ArrayView ( T *  array_ptr,
size_t  array_size 
)

Construct an array view from a pointer to a buffer.

Parameters
array_ptrPointer to the array data
array_sizeNumber of elements of T present in the array.
Postcondition
a call to size() will return array_size and data() will return array_tpr.

Definition at line 90 of file ArrayView.h.

ArrayView ( T(&)  elements[Size])

Construct an array view from the reference to an array.

Parameters
elementsReference to the array viewed.
Template Parameters
SizeNumber of elements of T presents in the array.
Postcondition
a call to size() will return Size, and data() will return a pointer to elements.

Definition at line 105 of file ArrayView.h.

Member Function Documentation

T* data ( )

Get the raw pointer to the array.

Returns
The raw pointer to the array.

Definition at line 151 of file ArrayView.h.

const T* data ( ) const

Get the raw const pointer to the array.

Returns
The raw pointer to the array.

Definition at line 161 of file ArrayView.h.

T& operator[] ( size_t  index)

Access to a mutable element of the array.

Parameters
indexElement index to access.
Returns
A reference to the element at the index specified in input.
Precondition
index shall be less than size().

Definition at line 127 of file ArrayView.h.

const T& operator[] ( size_t  index) const

Access to an immutable element of the array.

Parameters
indexElement index to access.
Returns
A const reference to the element at the index specified in input.
Precondition
index shall be less than size().

Definition at line 141 of file ArrayView.h.

size_t size ( ) const

Return the size of the array viewed.

Returns
The number of elements present in the array viewed.

Definition at line 113 of file ArrayView.h.

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.