This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: <string> - warning messages




Benjamin Kosnik wrote:
> 
> >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;
> 
I don't see how it will help because if distance is negative the program
will die miserably in _S_copy_chars(_M_data() + __off, __j1, __j2) a few
lines below.
So, if there is no intention to undertake something with it,

size_type __dnew = static_cast<size_type>(distance(__j1, __j2));

is ok.
Vadim.
-- 
*********************************************
Vadim Egorov, 1C      *       Вадим Егоров,1C
egorovv@1c.ru         *         egorovv@1c.ru
*********************************************


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]