Re: (const) iterator question
On Mar 22, 3:45 am, AlbertoBarb...@libero.it (Alberto Ganesh Barbati)
wrote:
James Kanze ha scritto:
some of the time. What he wants is:
TokenIterator lastSignificantToken = tokenList.end() ;
I thought he wanted lastSignificantToken to be initialized with a
singular value (in case there is one), but tokenList.end() is valid
past-the-end iterator. Of course it might do, but it's not exactly the same.
I know, and I'll admit that I'm really just guessing about what
he needs, from the name of the variable. I probably should have
been more explicit, but the names he used suggested that his
code was a misunderstood attempt at the two iterator idiom.
The STL idiom turns very heavily around the concept of the end
iterator. Just replacing a NULL pointer with the end iterator
won't, in general, work, but re-writing the code a bit to
conform to the STL conventions probably will. And when one has
access to the container (or an end iterator), container.end()
can almost always serve as a sentinal value as well. Again,
guessing at what he wanted, he will do something like:
while ( tokenIterator != tokenList.end() ) }
if ( isSignificantToken( *tokenIterator ) ) {
lastSignificantToken = tokenIterator ;
}
++ tokenIterator ;
}
If he finds no significant tokens, lastSignificantToken will
still be set to tokenList.end(), which can then be tested as a
sentinal value. (I agree that it's not as intuitive as a
special value, like NULL, but it is the STL convention.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]