I think the way to do this is through transposing the matrix:
std::vector<std::vector<int>> transpose(const std::vector<std::vector<int>> &m)
{
using std::vector;
vector<vector<int>> result(m[0].size(), vector<int>(m.size()));
for (vector<int>::size_type i(0); i < m[0].size(); ++i)
for (vector<int>::size_type j(0); j < m.size(); ++j)
result[i][j] = m[j][i];
return result;
}
and
std::vector<std::vector<int>>::iterator itCol;
std::vector<int>::iterator itRow;
std::vector<std::vector<int>> t(transpose(vMatrix));
for (itRow = t.begin(); itRow != t.end(); itRow++)
for (itCol = itRow->begin(); itCol != itRow->end(); itCol++)
{
}
Nothing should change inside the body of the cycle, but it is SLOW.
You can get some rate of change transposeto return the "representation" of the matrix transpose:
std::vector<std::vector<int *>> transpose(const std::vector<std::vector<int>> &)
In any case, even this solution is slower than accessing items through operator[].
, , 1D- (- fooobar.com/questions/685697/...).