Skip to content

Add operator + to sparse matrix iterator

Submitted by Valentin Roussellet

Assigned to Valentin Roussellet

Link to original bugzilla bug (#1340)
Version: 3.3 (current stable)

Description

SparseCompressedBase::InnerIterator has operator++ but no operator += or operator +

There are cases where one may want to advance the operator by N elements. Currently, the only way to do it is with a for loop such as :

for (i = 0; i < N; ++i,++iterator) {}

An addition operator is easy to define within the iterator :

inline InnerIterator& operator+=( _Index i ) { m_id += i; return *this; }

inline InnerIterator operator+( _Index i )

{

InnerIterator result = *this;  

result += i;  

return result;  

}

Similarly, a substraction operator can be added to ReverseIterator

inline ReverseInnerIterator& operator-=( _Index i ) { m_id -= i; return *this; }

inline ReverseInnerIterator operator-( _Index i )

{

ReverseInnerIterator result = *this;  

result -= i;  

return result;  

}

Blocking

#814