I ran into a curious problem evaluating expressions:
reference operator()(size_type i, size_type j) { return by_index(i, j, index)(i, j); // return matrix index reference with changed i, j } matrix& by_index(size_type &i, size_type &j, index_vector &index) { size_type a = position(i, index); // find position of i using std::upper_bound size_type b = position(j, index); i -= index[a]; j -= index[b]; return matrix_(a,b); // returns matrix reference stored in 2-D array }
I thought that the matrix (i, j) would be evaluated after calling buy_index, so that i, j would be updated. this seems correct, i checked in the debugger. however, for some types of matrices, in particular those that should be distinguished by size_type something else, for example int, the update in by_index is lost. changing the code fixes the problem a bit:
reference operator()(size_type i, size_type j) { matrix &m = by_index(i, j, index); return m(i, j); }
Do you know why the first statement fails? thanks
prototypes that work and which
inline reference operator () (size_t i, size_t j);
on the backdrace stack of the debugger is as follows:
- i = 1 when entering the operator () // okay
- i = 0 after completion with by_index // okay
- i = 1 when entering into the matrix :: operator () // not correct, should be 0