Writing a custom iterator -- what to do if you're at the end of the array?
Posted
by Goose Bumper
on Stack Overflow
See other posts from Stack Overflow
or by Goose Bumper
Published on 2010-04-24T23:19:45Z
Indexed on
2010/04/24
23:23 UTC
Read the original article
Hit count: 267
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?
© Stack Overflow or respective owner