I am looking for a way to iterate over elements of a Boost matrix using iterators. Documentation reports Matrix methods returning an iterator1 and iterator2:
iterator1 begin1 () Returns a iterator1 pointing to the beginning of the matrix.
iterator1 end1 () Returns a iterator1 pointing to the end of the matrix.
iterator2 begin2 () Returns a iterator2 pointing to the beginning of the matrix.
iterator2 end2 () Returns a iterator2 pointing to the end of the matrix.
I tried iterating over them, and iterator1 goes over the first column of the matrix (only), and iterator2 over the first row (only).
How are these iterator1 and iterator2 meant to be used?
It turns out the two iterators allow iterating over a matrix by row or by column, as you need. There is an answer at the link reported by CuriouslyRecurringThoughts , but I also give an example of usage with my code here, to anyone interested. The program below fills this matrix of integers
then prints it, first by rows and then by columns.
This is the output: