This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: <string> - warning messages
- To: libstdc++@sourceware.cygnus.com
- Subject: Re: <string> - warning messages
- From: Benjamin Kosnik <bkoz@cygnus.com>
- Date: Tue, 29 Jun 1999 17:22:01 -0700
>It's a lot worse than that. This makes the function incompatible with
>real Input iterators, because measuring the distance uses them up.
>They're one-pass items.
Hmm. Well, in the two functions that use distance are specialized for
forward_iterator tags:
_M_replace(iterator __i1, iterator __i2, _ForwardIter __j1,
_ForwardIter __j2, forward_iterator_tag)
// check distance here
_M_replace(iterator __i1, iterator __i2, _InputIter __j1,
_InputIter __j2, input_iterator_tag)
// but not here
and
_S_construct(_InIter __beg, _InIter __end, const _Alloc& __a,
forward_iterator_tag)
// check here
_S_construct(_InIter __beg, _InIter __end, const _Alloc& __a,
input_iterator_tag)
// but not here
So I think these are safe for one-pass interators. The fundamental
question remains though: what's the best way for the
forward_iterator_tag versions to check the iterator distances? The
distance function returns a signed difference_type, yet size() returns
an unsigned type: comparisons between signed and unsigned are not
kosher, so I figure the best approach is to do something like:
difference_type __dnews = distance(__j1, __j2);
__denews = __dnews > 0 ? __dnews : -1 * __dnews;
size_type __dnew = static_cast<size_type>(__dnews);
or
size_type __dnew = __j2 -__j1;
Note this is also the issue surrounding the reported bug in
stl_deque.h with -Wall.
The __get_c_string stuff has been removed. I missed stl_string_fwd.h
when I took it out of everywhere else, apparently. I just fixed this,
but thanks again for pointing it out.
-Benjamin