Great, thanks. I got your second email, but even the previous buggy patch was enough to let me make progress. I'll wait with the new patch until I hear that you're happy with it.
It's in cvs now, as far as I can tell (and I've added quite a few new test cases), the third patch is finally correct.
I think the original code is relatively fine as long as the operator++ doesnt have to do a lot of work or dereference the iterators. The iterator I'm using has the property that I dont know the distance to the end or how to answer the question
iter == end
without dereferencing(reading) the whole input.
Yikes, that's going to really kill things, the code has to be able to tell whether it's reached the end of the sequence or not, and iter == end is evaluated frequently. One option may be to change your iterator implementation to use a special "singular" value for end-of-sequence, so that particular comparison then becomes trivial. HTH, John.