Consider standard algorithms like, say, std::for_each
.
template
Function for_each(InputIterator first
Does that mean that the following is technically valid? Or is it undefined? What can I realistically expect it to do?
No it is not. Your code would exhibit undefined behavior when for_each
increments the iterator and that iterator would be pointing to end
and there is nothing to dereference(Well, it is enough to get undefined behavior at this point, so there is no point talking about past end)!