Boost logo

Boost Users :

From: David McKelvie (david_at_[hidden])
Date: 2005-03-30 08:40:33


>> 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.

Great. Thanks for your help in this.

Is what you emailed me the same as what is now in CVS?
(I havent used the CVS before - but it may be time to learn)

>> 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

>> 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.

Yes, that's what I do do. I probably didnt explain myself very well.
But it's the operator++ that has to read input.

TokenSource::iterator & TokenSource::iterator::operator++(){ // prefix ++X
  ++bp;
  get_stuff();
  return *this;
}
void TokenSource::iterator::get_stuff(){
  string a;
  if( bp >= fb->my_finish ){ // Run off end - read more
    if( fb->p->eof() ){
      bp = -1; // special value for end() iterator
    } else {
      getline(*(fb->p),a);
      fb->inc_line_number();
      fb->add_stuff(a+"\n");
    }
  }
}
bool TokenSource::iterator::operator==(const TokenSource::iterator &x) const {
  return ( fb == x.fb ) && ( bp == x.bp );
}

Anyway, I could implement it differently and put get_stuff in operator*
and even in the case of a straight-forward
string::iterator your patch now avoids doing many additions in the case of
a very long string.

  David


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net