Denislam Valeev / Mbed OS Nucleo_rtos_basic
Embed: (wiki syntax)

« Back to documentation index

ArrayView< T > Struct Template Reference

ArrayView< T > Struct Template Reference

Immutable view to an array. More...

#include <ArrayView.h>

Public Member Functions

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

Friends

bool operator== (const ArrayView &lhs, const ArrayView &rhs)
 Equality operator.
bool operator!= (const ArrayView &lhs, const ArrayView &rhs)
 Not equal operator.

Detailed Description

template<typename T>
struct ble::ArrayView< T >

Immutable view to an array.

Array views encapsulate the pointer to an array and its size into a single object; 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().
Template Parameters:
Ttype of objects held by the array.

Definition at line 54 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 61 of file ArrayView.h.

ArrayView ( T *  array_ptr,
size_t  array_size 
)

Construct an array view from a pointer to a buffer and its size.

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 72 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 86 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 132 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 142 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 108 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 122 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 94 of file ArrayView.h.


Friends And Related Function Documentation

bool operator!= ( const ArrayView< T > &  lhs,
const ArrayView< T > &  rhs 
) [friend]

Not equal operator.

Parameters:
lhsLeft hand side of the binary operation.
rhsRight hand side of the binary operation.
Returns:
True if arrays in input do not have the same size or the same content and false otherwise.

Definition at line 178 of file ArrayView.h.

bool operator== ( const ArrayView< T > &  lhs,
const ArrayView< T > &  rhs 
) [friend]

Equality operator.

Parameters:
lhsLeft hand side of the binary operation.
rhsRight hand side of the binary operation.
Returns:
True if arrays in input have the same size and the same content and false otherwise.

Definition at line 156 of file ArrayView.h.