Topic: Add basic_string::resize_uninitialized (or a similar mechanism)


Author: amluto@gmail.com
Date: Mon, 18 Nov 2013 12:41:59 -0800 (PST)
Raw View
------=_Part_599_14216815.1384807319510
Content-Type: text/plain; charset=ISO-8859-1

There are many mechanisms around that create basic_string objects that
contain some form of formatted data (e.g. ostringstream, to_string).
Unfortunately, there is currently no way to obtain a basic_string of
nonzero size and interesting contents without either composing the contents
externally and copying or writing to the string twice.

The former can be achieved by composing the contents of the string as an
array or a sequence and using the basic_string constructors.  The latter
can be achieved by using resize() and operator[] to create a blank string
and fill it in.

For applications where a reasonable approximation of the final size of the
string is known in advance (or where users are willing to over-allocate),
it's tempting to try to optimize by resizing the string and composing in
place.  This wastes time because basic_string::resize() always fully
initializes the string.

If basic_string had a method like resize_uninitialized that changed the
size of the underlying array but did *not* construct the elements (with
similar semantics to declaring an uninitialized local variable of type
char).  This would only be allowed for sufficiently trivial character types.

(std::vector has much the same issue.)

Thoughts?

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_599_14216815.1384807319510
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">There are many mechanisms around that create basic_string =
objects that contain some form of formatted data (e.g. ostringstream, to_st=
ring).&nbsp; Unfortunately, there is currently no way to obtain a basic_str=
ing of nonzero size and interesting contents without either composing the c=
ontents externally and copying or writing to the string twice.<br><br>The f=
ormer can be achieved by composing the contents of the string as an array o=
r a sequence and using the basic_string constructors.&nbsp; The latter can =
be achieved by using resize() and operator[] to create a blank string and f=
ill it in.<br><br>For applications where a reasonable approximation of the =
final size of the string is known in advance (or where users are willing to=
 over-allocate), it's tempting to try to optimize by resizing the string an=
d composing in place.&nbsp; This wastes time because basic_string::resize()=
 always fully initializes the string.<br><br>If basic_string had a method l=
ike resize_uninitialized that changed the size of the underlying array but =
did *not* construct the elements (with similar semantics to declaring an un=
initialized local variable of type char).&nbsp; This would only be allowed =
for sufficiently trivial character types.<br><br>(std::vector has much the =
same issue.)<br><br>Thoughts?<br></div>

<p></p>

-- <br />
&nbsp;<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_599_14216815.1384807319510--

.