Main Content

matlab::data::Reference<T>

Templated C++ class to get references to Array elements

Description

A Reference object is a reference to an element of an Array without making a copy. A Reference is:

  • Not a shared copy

  • Valid as long as the array that contains the reference is valid

  • Not thread-safe

Class Details

Namespace:

matlab::data

Include:

Reference.hpp

Template Parameters

T

Type of element referred to, specified as:

  • Array

  • Struct

  • Enumeration

  • MATLABString

  • All std::complex types

Constructors

Copy Constructor

Reference(const Reference<T>& rhs)

Parameters

const Reference<T>& rhs

Value to copy.

Copy Assignment Operators

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

Parameters

const Reference<T>& rhs

Value to copy.

Returns

Reference<T>&

Updated instance.

Move Assignment Operators

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

Parameters

Reference<T>&& rhs

Value to move.

Returns

Reference<T>&

Updated instance.

Throws

None

Move Constructors

Reference(Reference<T>&& rhs)

Description

Moves contents of a Reference object to a new instance.

Parameters

Reference<T>&& rhs

Value to move.

Throws

None

Other Operators

operator=

Reference<T>& operator=(T rhs)

Reference<T>& operator=(std::string rhs)

Reference<T>& operator=(String rhs)

Parameters

T rhs

Value to assign. The indexed array must be non-const.

std::string rhs

String to assign. The array must be non-const and allow strings to be assigned.

String rhs

String to assign to StringArray. The indexed array must be non-const.

Returns

Reference<T>&

Updated instance.

Throws

None

operator<<

std::ostream& operator <<(std::ostream& os, Reference<T> const& rhs)

Parameters

std::ostream& os

 

Reference<T> const& rhs

 
Returns

std::ostream&

 

operator T()

operator T() const

Description

Cast to element from the array.

Returns

T

Shared copy of element from array.

Throws

None

operator std::string()

operator std::string() const

Description

Casts array to std::string, making a copy of the std::string. This operator is valid only for types that can be cast to a std::string.

Returns

std::string

String.

Throws

matlab::data::NonAsciiCharInInputDataException

Input is std::string and contains non-ASCII characters.

std::runtime_error

MATLABString is missing.

Free Functions

operator==

inline bool operator ==(Reference<MATLABString> const& lhs, std::string const& rhs)

inline bool operator ==(std::string const& lhs, Reference<MATLABString> const& rhs)

inline bool operator ==(Reference<MATLABString> const& lhs, String const& rhs)

inline bool operator ==(String const& lhs, Reference<MATLABString> const& rhs)

inline bool operator ==(Reference<MATLABString> const& lhs, MATLABString const& rhs)

inline bool operator ==(MATLABString const& lhs, Reference<MATLABString> const& rhs)

inline bool operator ==(Reference<MATLABString> const& lhs, Reference<MATLABString> const& rhs)

template<typename T> bool operator ==(Reference<T> const& lhs, T const& rhs)

template<typename T> bool operator ==(T const& lhs, Reference<T> const& rhs)

template<typename T> bool operator ==(Reference<T> const& lhs, Reference<T> const& rhs)

Parameters

Reference<MATLABString> const& lhs

std::string const& rhs

Values to compare.

std::string const& lhs

Reference<MATLABString> const& rhs

Reference<MATLABString> const& lhs

String const& rhs

String const& lhs

Reference<MATLABString> const& rhs

Reference<MATLABString> const& lhs

MATLABString const& rhs

MATLABString const& lhs

Reference<MATLABString> const& rhs

Reference<MATLABString> const& lhs

Reference<MATLABString> const& rhs

Reference<T> const& lhs

T const& rhs

T const& lhs

Reference<T> const& rhs

Reference<T> const& lhs

Reference<T> const& rhs

Returns

bool

Returns true if values are equal.

Throws

std::runtime_error

Cannot compare argument to MATLABString.

Version History

Introduced in R2017b