VectorIterator steps a Vector (the "cursor") through an array. The cursor "refers" to storage in the array, so that changing the values in the cursor changes values in the original array. Like with ArrayPositionIterator, the cursor presently only moves through the array from bottom to top in the obvious way; however one may of course iterate through a slice ("array section"). This class is derived from ArrayIterator; basically it only adds the vector() member function which allows you to access the cursor as a Vector.
The origin of the cursor, i.e. the subarray that moves through the larger array, is always zero.In this example we sum all the elements of an array; of course we already have the "sum" function in ArrayMath.h that we should use instead.
Array<Float> af; // set af VectorIterator vi(af); Float sum = 0.0; uInt n = vi.vector().nelements(); while (! vi.pastEnd()) { for (Int i=0; i < n; i++) { // N.B.; cursor always 0 based. sum += vi.vector()(i); } vi.next(); }
All ArrayIterator classes should be redone.
Not implemented.
Return a Vector at the current position.
ReadOnlyVectorIterator behaves exactly like VectorIterator (cf.) only it should be used on const Arrays.
Note that the R/O VectorIterator is not derived from R/O ArrayIterator.