Let's say I have a Matrix
class I've already implemented.
Matrix<float> mat(30, 30);
for(size_t row = 0; row < mat.rows(); row++) {//Assume Row-Major ordering for performance reasons
for(size_t column = 0; column < mat.columns(); column++) {
mat(row, column) = float(row+1) / float(column+1);
}
}
I'd like to add to this implementation some concepts of "Row Iterator" and "Column Iterator". Some kind of interface like the following:
//public:
row_iterator begin_row(size_t row); //Is this intuitive?
const_row_iterator begin_row(size_t row) const;
const_row_iterator cbegin_row(size_t row) const;
row_iterator end_row(size_t row);
const_row_iterator end_row(size_t row) const;
const_row_iterator cend_row(size_t row) const;
//Same for column iterators
The issue is that it's not clear to me what behavior is intuitive for most users. My instinct is that a "Row Iterator" iterates "within" the row, i.e,
auto begin = mat.begin_row(1);
auto end = mat.end_row(1);
for(; begin < end; ++begin) *begin = 5.f;//Fills the second row with the value 5.
However, it occurs to me that some users might expect a "Row Iterator" to iterate "across" rows, i.e.
auto begin = mat.begin_row(1);
auto end = mat.end_row(1);
for(; begin < end; ++begin) *begin = 5.f;//Fills the second column with the value 5.
Implementing either version of this code is (theoretically) trivial, but which behavior seems more intuitive to an average user? Is there a better design that avoids this ambiguity?