Writing a custom iterator -- what to do if you're at the end of the array?
- by Goose Bumper
I'm writing a custom iterator for a Matrix class, and I want to implement the increment method, which gets called when the iterator is incremented:
void MatrixIterator::increment()
{
// go to the next element
}
Suppose the iterator has been incremented too many times and now points to past the end of the matrix (i.e. past the one-past-the-end point). What is the best practice for this situation? Should I catch this with an assert, or should I just say it's the user's responsibility to keep track of where the iterator is pointing and it's none of my business?