M
mathog
What does one do in this situation:
....
Glib::ustring::const_iterator icc;
....
icc = _spans[lastspan].input_stream_first_character;
....
// need a test here to see if the next line is safe
if(*icc){
In the textbook examples one has both the vector and the iterator, so
the test can be rolled together on one line like:
if(icc != avector.end() && *icc)
In this case it isn't entirely clear which vector that iterator is
referencing. (Because _spans hangs onto the iterator but does not
store the vector, at least not publicly.) It might (might!) be possible
to hunt the vector down, by chasing backwards through half a dozen
objects to find it, but why should that be necessary? Is there not in
C++ something like:
if(icc->dereferencable()){
?
This came up in a situation where an empty text span was embedded
between others with characters. So on the 3rd span (or whatever it was)
the value of icc was set to a non-dereferencable value from the get go,
that value having been stored there long ago and far away in the code.
Of course without the missing test the program segfaulted when it tried
to dereference the const_iterator for this empty span.
I suppose that the desired result could be accomplished with try/catch,
but wonder if C++ iterators do not in general have some method for doing
this.
Thank you,
David Mathog
....
Glib::ustring::const_iterator icc;
....
icc = _spans[lastspan].input_stream_first_character;
....
// need a test here to see if the next line is safe
if(*icc){
In the textbook examples one has both the vector and the iterator, so
the test can be rolled together on one line like:
if(icc != avector.end() && *icc)
In this case it isn't entirely clear which vector that iterator is
referencing. (Because _spans hangs onto the iterator but does not
store the vector, at least not publicly.) It might (might!) be possible
to hunt the vector down, by chasing backwards through half a dozen
objects to find it, but why should that be necessary? Is there not in
C++ something like:
if(icc->dereferencable()){
?
This came up in a situation where an empty text span was embedded
between others with characters. So on the 3rd span (or whatever it was)
the value of icc was set to a non-dereferencable value from the get go,
that value having been stored there long ago and far away in the code.
Of course without the missing test the program segfaulted when it tried
to dereference the const_iterator for this empty span.
I suppose that the desired result could be accomplished with try/catch,
but wonder if C++ iterators do not in general have some method for doing
this.
Thank you,
David Mathog