This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] Assign(__str, __pos, __n) (take3) + Assign(__s, __n)
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: Nathan Myers <ncm-nospam at cantrip dot org>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Sat, 15 Dec 2001 20:55:47 +0100
- Subject: Re: [PATCH] Assign(__str, __pos, __n) (take3) + Assign(__s, __n)
- References: <3C1B6AC9.BE4BCEF9@unitus.it> <20011215194057.A63133@cantrip.org>
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.