RowMajorIterator< M, IsConst > Class Template Reference

CPP API: mio::RowMajorIterator< M, IsConst > Class Template Reference
mio::RowMajorIterator< M, IsConst > Class Template Reference

iterate over elements of eigen matrix expressions in row major order. More...

#include <eigen_util.h>

Classes

struct  Proxy
 

Public Types

using difference_type = Eigen::Index
 
using iterator_category = std::random_access_iterator_tag
 
using MatrixPtr = std::conditional_t< IsConst, const M *, M * >
 
using MatrixRef = std::conditional_t< IsConst, const M &, M & >
 
using pointer = std::conditional_t< details::IsElementReference< MatrixRef >, std::conditional_t< IsConst, const value_type *, value_type * >, Proxy >
 
using reference = std::conditional_t< IsConst, const value_type &, value_type & >
 
using value_type = typename M::Scalar
 

Public Member Functions

bool operator!= (const RowMajorIterator &other) const
 inequality comparison operator. More...
 
decltype(auto) operator* () const
 dereference this to get the element pointed to. More...
 
RowMajorIterator operator+ (difference_type n) const
 random access, add n to index of this. More...
 
RowMajorIteratoroperator++ ()
 pre increment operator. More...
 
RowMajorIterator operator++ (int)
 post increment operator. More...
 
RowMajorIteratoroperator+= (difference_type n)
 add n to index of this. More...
 
RowMajorIterator operator- (difference_type n) const
 take n from the index of this. More...
 
difference_type operator- (RowMajorIterator r) const
 calculate the distance between this and r. More...
 
RowMajorIteratoroperator-- ()
 pre decrement operator. More...
 
RowMajorIterator operator-- (int)
 post decrement operator. More...
 
RowMajorIteratoroperator-= (difference_type n)
 take n from the index of this. More...
 
bool operator< (const RowMajorIterator &other) const
 lesser comparison operator. More...
 
bool operator<= (const RowMajorIterator &other) const
 lesser equal comparison operator. More...
 
bool operator== (const RowMajorIterator &other) const
 equality comparison operator. More...
 
bool operator> (const RowMajorIterator &other) const
 greater than comparison operator. More...
 
bool operator>= (const RowMajorIterator &other) const
 greater equal comparison operator. More...
 
 RowMajorIterator ()
 
 RowMajorIterator (MatrixRef m, Eigen::Index i)
 Create an iterator that points to a specific element. More...
 
pointer operator-> () const requires details
 get a pointer to the element this iterator points to. More...
 

Private Attributes

Eigen::Index m_i
 
MatrixPtr m_matrix
 

Friends

RowMajorIterator operator+ (difference_type n, const RowMajorIterator &iter)
 random access, add n to index of iterator. More...
 

Detailed Description

template<class M, bool IsConst = false>
class mio::RowMajorIterator< M, IsConst >

iterate over elements of eigen matrix expressions in row major order.

Template Parameters
Man eigen matrix expression type, can be in memory or lazy.
IsConsttrue if the elements of the matrix are not modifiable.

Member Typedef Documentation

◆ difference_type

template<class M , bool IsConst = false>
using mio::RowMajorIterator< M, IsConst >::difference_type = Eigen::Index

◆ iterator_category

template<class M , bool IsConst = false>
using mio::RowMajorIterator< M, IsConst >::iterator_category = std::random_access_iterator_tag

◆ MatrixPtr

template<class M , bool IsConst = false>
using mio::RowMajorIterator< M, IsConst >::MatrixPtr = std::conditional_t<IsConst, const M*, M*>

◆ MatrixRef

template<class M , bool IsConst = false>
using mio::RowMajorIterator< M, IsConst >::MatrixRef = std::conditional_t<IsConst, const M&, M&>

◆ pointer

template<class M , bool IsConst = false>
using mio::RowMajorIterator< M, IsConst >::pointer = std::conditional_t<details::IsElementReference<MatrixRef>, std::conditional_t<IsConst, const value_type*, value_type*>, Proxy>

◆ reference

template<class M , bool IsConst = false>
using mio::RowMajorIterator< M, IsConst >::reference = std::conditional_t<IsConst, const value_type&, value_type&>

◆ value_type

template<class M , bool IsConst = false>
using mio::RowMajorIterator< M, IsConst >::value_type = typename M::Scalar

Constructor & Destructor Documentation

◆ RowMajorIterator() [1/2]

template<class M , bool IsConst = false>
mio::RowMajorIterator< M, IsConst >::RowMajorIterator ( MatrixRef  m,
Eigen::Index  i 
)
inline

Create an iterator that points to a specific element.

Indexing is done by flat indices i = r * nc + c where r is the row index, c is the column index and nc is the number of columns.

Parameters
mreference of a matrix expression. Only a reference is stored, mind the lifetime of the object.
iflat index of the element pointed to.

◆ RowMajorIterator() [2/2]

template<class M , bool IsConst = false>
mio::RowMajorIterator< M, IsConst >::RowMajorIterator ( )
inlineexplicit

Member Function Documentation

◆ operator!=()

template<class M , bool IsConst = false>
bool mio::RowMajorIterator< M, IsConst >::operator!= ( const RowMajorIterator< M, IsConst > &  other) const
inline

inequality comparison operator.

◆ operator*()

template<class M , bool IsConst = false>
decltype(auto) mio::RowMajorIterator< M, IsConst >::operator* ( ) const
inline

dereference this to get the element pointed to.

may return a temporary value instead of a reference to the element if the matrix is not evaluated in memory, e.g. in the case of Eigen::MatrixXd::Constant(r, c, v).

◆ operator+()

template<class M , bool IsConst = false>
RowMajorIterator mio::RowMajorIterator< M, IsConst >::operator+ ( difference_type  n) const
inline

random access, add n to index of this.

◆ operator++() [1/2]

template<class M , bool IsConst = false>
RowMajorIterator& mio::RowMajorIterator< M, IsConst >::operator++ ( )
inline

pre increment operator.

◆ operator++() [2/2]

template<class M , bool IsConst = false>
RowMajorIterator mio::RowMajorIterator< M, IsConst >::operator++ ( int  )
inline

post increment operator.

◆ operator+=()

template<class M , bool IsConst = false>
RowMajorIterator& mio::RowMajorIterator< M, IsConst >::operator+= ( difference_type  n)
inline

add n to index of this.

◆ operator-() [1/2]

template<class M , bool IsConst = false>
RowMajorIterator mio::RowMajorIterator< M, IsConst >::operator- ( difference_type  n) const
inline

take n from the index of this.

◆ operator-() [2/2]

template<class M , bool IsConst = false>
difference_type mio::RowMajorIterator< M, IsConst >::operator- ( RowMajorIterator< M, IsConst >  r) const
inline

calculate the distance between this and r.

◆ operator--() [1/2]

template<class M , bool IsConst = false>
RowMajorIterator& mio::RowMajorIterator< M, IsConst >::operator-- ( )
inline

pre decrement operator.

◆ operator--() [2/2]

template<class M , bool IsConst = false>
RowMajorIterator mio::RowMajorIterator< M, IsConst >::operator-- ( int  )
inline

post decrement operator.

◆ operator-=()

template<class M , bool IsConst = false>
RowMajorIterator& mio::RowMajorIterator< M, IsConst >::operator-= ( difference_type  n)
inline

take n from the index of this.

◆ operator->()

template<class M , bool IsConst = false>
pointer mio::RowMajorIterator< M, IsConst >::operator-> ( ) const
inline

get a pointer to the element this iterator points to.

may return a proxy instead of a reference to the element if the matrix is not evaluated in memory, e.g. in the case of Eigen::MatrixXd::Constant(r, c, v). The proxy stores a copy of the element and forwards the address of this copy.

◆ operator<()

template<class M , bool IsConst = false>
bool mio::RowMajorIterator< M, IsConst >::operator< ( const RowMajorIterator< M, IsConst > &  other) const
inline

lesser comparison operator.

◆ operator<=()

template<class M , bool IsConst = false>
bool mio::RowMajorIterator< M, IsConst >::operator<= ( const RowMajorIterator< M, IsConst > &  other) const
inline

lesser equal comparison operator.

◆ operator==()

template<class M , bool IsConst = false>
bool mio::RowMajorIterator< M, IsConst >::operator== ( const RowMajorIterator< M, IsConst > &  other) const
inline

equality comparison operator.

◆ operator>()

template<class M , bool IsConst = false>
bool mio::RowMajorIterator< M, IsConst >::operator> ( const RowMajorIterator< M, IsConst > &  other) const
inline

greater than comparison operator.

◆ operator>=()

template<class M , bool IsConst = false>
bool mio::RowMajorIterator< M, IsConst >::operator>= ( const RowMajorIterator< M, IsConst > &  other) const
inline

greater equal comparison operator.

Friends And Related Function Documentation

◆ operator+

template<class M , bool IsConst = false>
RowMajorIterator operator+ ( difference_type  n,
const RowMajorIterator< M, IsConst > &  iter 
)
friend

random access, add n to index of iterator.

Member Data Documentation

◆ m_i

template<class M , bool IsConst = false>
Eigen::Index mio::RowMajorIterator< M, IsConst >::m_i
private

◆ m_matrix

template<class M , bool IsConst = false>
MatrixPtr mio::RowMajorIterator< M, IsConst >::m_matrix
private