Main Content

matlab::data::Reference<TypedArray<T>>

Templated C++ class to get reference to TypedArray

Description

The Reference<TypedArray<T>> class extends the APIs available to a reference to an Array. It derives from the Reference<Array> class and provides iterators and type-safe indexing. Use to modify the elements of a container such as a struct or cell.

Reference<TypedArray<T>> is not thread-safe - do not pass references to TypedArray objects between threads.

TypedArrayRef is defined in TypedArrayRef.hpp as:

template <typename T>
using TypedArrayRef = Reference<TypedArray<T>>;

Class Details

Namespace:

matlab::data

Base class:

Reference<Array>

Include:

TypedArrayRef.hpp

Constructor

Reference(const Reference<Array>& rhs)

Description

Create a Reference<TypedArray<T>> object from a Reference<Array> object.

Parameters

const Reference<Array>& rhs

Value to copy.

Throws

matlab::data::TypeMismatchException

Element of Array does not match <T>.

Iterators

Begin Iterators

iterator begin()

const_iterator begin() const

const_iterator cbegin() const

Returns

iterator

Iterator to beginning of array, specified as TypedIterator<T>.

const_iterator

Iterator, specified as TypedIterator<typename std::add_const<T>::type>.

Throws

None

End Iterators

iterator end()

const_iterator end() const

const_iterator cend() const

Returns

iterator

Iterator to end of array, specified as TypedIterator<T>.

const_iterator

Iterator, specified as TypedIterator<typename std::add_const<T>::type>.

Throws

None

Indexing Operators

operator[]

ArrayElementTypedRef<arr_elem_type, std::is_const<T>::value> operator[](size_t idx)

ArrayElementTypedRef<arr_elem_type, true> operator[](size_t idx) const

Description

Enables [] indexing on a reference to an Array. Indexing is 0-based.

Parameters

size_t idx

First array index.

Returns

ArrayElementTypedRef<arr_elem_type, std::is_const<T>::value>

Temporary object containing index specified. If type T is const, then the return value allows the element of the array to be retrieved, but not modified. Otherwise, the element can be modified or retrieved.

ArrayElementTypedRef<arr_elem_type, true>

Temporary object containing index specified. The return value allows the element of the array to be retrieved, but not modified.

Throws

matlab::data::InvalidFieldNameException

Field name is invalid for a struct.

Other Operators

operator=

Reference<TypedArray<T>>& operator= (TypedArray<T> rhs)

Description

Assign a TypedArray to an element of the referenced Array. The Array being indexed must be non-const.

Parameters

TypedArray<T> rhs

Value to assign.

Returns

Reference<TypedArray<T>>&

Updated instance.

Throws

None

Version History

Introduced in R2017b