[PATCH] Assign(__str, __pos, __n) (take3) + Assign(__s, __n)

Paolo Carlini pcarlini@unitus.it
Sat Dec 15 11:56:00 GMT 2001


Nathan Myers wrote:

> On Sat, Dec 15, 2001 at 04:22:49PM +0100, Paolo Carlini wrote:
> > ... In the meanwhile I have also prepared the new
> > assign(const _CharT* __s, size_type __n) > (similar general structure),
> > based on http://gcc.gnu.org/ml/libstdc++/2001-12/msg00215.html.
> >
> > !  if (__n > this->max_size())
> > !    __throw_length_error("basic_string::assign");
> > !  if (_M_rep()->_M_is_shared() || __s < _M_data()
> > !      || __s > _M_data() + this->size())
> > !    return _M_replace_safe(_M_ibegin(), _M_iend(), __s, __s + __n);
> > !  else
>
> Two thoughts.  First, for portability we cannot compare two pointers
> directly that are not pointing into the same array.  (The mistake may
> occur in the existing code, mea culpa.)  However, we can use std::less<>
> to do the same thing safely.  Second, this version is more general and
> might be used to implement the other, although at the cost of an extra
> comparison.

Thanks.
Is it ok with you if, for time being, I test and then commit a version including
only the first improvement, that is, using std::less??

Paolo.




More information about the Libstdc++ mailing list