[v3] basic_string::reserve() shrink-to-fit?
Paolo Carlini
pcarlini@unitus.it
Thu Dec 11 15:04:00 GMT 2003
Neil Ferguson wrote:
> template<typename _CharT, typename _Traits, typename _Alloc>
> void
> basic_string<_CharT, _Traits, _Alloc>::reserve(size_type __res)
> {
> >> if (__res != this->capacity() || _M_rep()->_M_is_shared())
> {
> if (__res > this->max_size())
> __throw_length_error("basic_string::reserve");
> // Make sure we don't shrink below the current size
> if (__res < this->size())
> __res = this->size();
> allocator_type __a = get_allocator();
> _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->size());
> _M_rep()->_M_dispose(__a);
> _M_data(__tmp);
> }
> }
>
> --
>
> so that __res only needs to be different from capacity(), rather than
> greater,
First blush (no testsuite, etc...), seems a good idea to me, Nathan?
Paolo.
More information about the Libstdc++
mailing list