matrix size must be calculated each time an iterator is constructed with end(). Maybe store the end() iterator as a member?