https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110945

--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #11)
> With this change we make a single allocation+copy and then do a cheap move
> assignment:
> 
> --- a/libstdc++-v3/include/bits/basic_string.h
> +++ b/libstdc++-v3/include/bits/basic_string.h
> @@ -1711,4 +1711,4 @@
>          basic_string&
>          assign(_InputIterator __first, _InputIterator __last)
> -        { return this->replace(begin(), end(), __first, __last); }
> +        { return *this = basic_string(__first, __last, get_allocator()); }

Except it's not cheap for C++98 because it's a copy, so we're back to
allocating and copying everything twice. That's solvable though.

Reply via email to