[range] Calculate the iterator distance in erase() only when necessary.