Theoretica
A C++ numerical and automatic mathematical library
theoretica::mat_iterator< Matrix, ReturnType > Class Template Reference

A sequential iterator for matrices. More...

#include <mat.h>

Public Types

using iterator_category = std::forward_iterator_tag
 
using value_type = matrix_element_t< Matrix >
 
using pointer = value_type *
 
using reference = value_type &
 

Public Member Functions

 mat_iterator (Matrix &matrix, size_t row=0, size_t col=0)
 Constructs an iterator for a matrix, optionally starting at a specified row and column. More...
 
ReturnType operator* ()
 Dereferences the iterator to access the current matrix element. More...
 
mat_iteratoroperator++ ()
 Advances the iterator to the next element in row-major order. More...
 
size_t row_index ()
 Retrieves the current row index of the iterator. More...
 
size_t col_index ()
 Retrieves the current column index of the iterator. More...
 
bool operator== (const mat_iterator &other) const
 Equality operator to compare two iterators. More...
 
bool operator!= (const mat_iterator &other) const
 Inequality operator to compare two iterators. More...
 

Detailed Description

template<typename Matrix, typename ReturnType = matrix_element_t<Matrix>&>
class theoretica::mat_iterator< Matrix, ReturnType >

A sequential iterator for matrices.

A const iterator may be constructed by specifying both typenames Matrix and ReturnType as const.

Constructor & Destructor Documentation

◆ mat_iterator()

template<typename Matrix , typename ReturnType = matrix_element_t<Matrix>&>
theoretica::mat_iterator< Matrix, ReturnType >::mat_iterator ( Matrix &  matrix,
size_t  row = 0,
size_t  col = 0 
)
inline

Constructs an iterator for a matrix, optionally starting at a specified row and column.

Parameters
matrixReference to the matrix to iterate over.
rowInitial row index for the iterator (default is 0).
colInitial column index for the iterator (default is 0).

Constructs an iterator that points to the specified initial position within the matrix. If no row and column are specified, the iterator starts at the matrix's top-left corner (0, 0).

Member Function Documentation

◆ col_index()

template<typename Matrix , typename ReturnType = matrix_element_t<Matrix>&>
size_t theoretica::mat_iterator< Matrix, ReturnType >::col_index ( )
inline

Retrieves the current column index of the iterator.

Returns
The column index as a size_t.

◆ operator!=()

template<typename Matrix , typename ReturnType = matrix_element_t<Matrix>&>
bool theoretica::mat_iterator< Matrix, ReturnType >::operator!= ( const mat_iterator< Matrix, ReturnType > &  other) const
inline

Inequality operator to compare two iterators.

Parameters
otherAnother iterator to compare with.
Returns
true if the iterators do not point to the same matrix element; otherwise, false.

◆ operator*()

template<typename Matrix , typename ReturnType = matrix_element_t<Matrix>&>
ReturnType theoretica::mat_iterator< Matrix, ReturnType >::operator* ( )
inline

Dereferences the iterator to access the current matrix element.

Returns
A reference (or const reference) to the matrix element at the current iterator position.

Provides direct access to the element at the iterator's current position.

◆ operator++()

template<typename Matrix , typename ReturnType = matrix_element_t<Matrix>&>
mat_iterator& theoretica::mat_iterator< Matrix, ReturnType >::operator++ ( )
inline

Advances the iterator to the next element in row-major order.

Returns
A reference to the updated iterator.

Moves the iterator one element forward within the matrix. When the end of a row is reached, it continues to the first element of the next row.

◆ operator==()

template<typename Matrix , typename ReturnType = matrix_element_t<Matrix>&>
bool theoretica::mat_iterator< Matrix, ReturnType >::operator== ( const mat_iterator< Matrix, ReturnType > &  other) const
inline

Equality operator to compare two iterators.

Parameters
otherAnother iterator to compare with.
Returns
true if the iterators point to the same matrix element; otherwise, false.

◆ row_index()

template<typename Matrix , typename ReturnType = matrix_element_t<Matrix>&>
size_t theoretica::mat_iterator< Matrix, ReturnType >::row_index ( )
inline

Retrieves the current row index of the iterator.

Returns
The row index as a size_t.

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