Normal iterator pointer behavior
I attempted to write a simple function that would apply an input function to all elements of an 'array'. The array is part of a complex class built to handle matrices from a third party. I had thought the normal behavior of the iterator is that derefence operator *iter can be used to both access and set the values of the underlying object. However this code leaves the original array (rm) unchanged.
Code:
/* apply a function to all elements of the array */
void rapp2self(cvm::rmatrix &rm, double (*dfunc)(double))
{
cvm::rmatrix::iterator q ;
for (q = rm.begin() ; q != rm.end() ; ++q) {
*q = (*dfunc) (*q) ;
}
}
The cvm library is an external matrix lib. that uses the std libraries to generate it's internal arrays (or so I thought). I suppose the *q itself could be overloaded here causing surprising results. I'm not even sure I have the source for the cvm library to check this. For a 'correctly' implemented iterator can I assume that I can assign to the object q points to via *q?