220 7334 <8d70b552-2ec1-45e7-9afb-dee28d73438a@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: jgottman6@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Suggestion: ostringstream::move_str()
Date: Wed, 16 Oct 2013 18:46:18 -0700 (PDT)
Lines: 87
Approved: news@gmane.org
Message-ID: <8d70b552-2ec1-45e7-9afb-dee28d73438a@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_370_21974380.1381974378963"
X-Trace: ger.gmane.org 1381974378 30409 80.91.229.3 (17 Oct 2013 01:46:18 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 17 Oct 2013 01:46:18 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD7LHGWIQEPRB3EC7WJAKGQECTBGT5I@isocpp.org Thu Oct 17 03:46:23 2013
Return-path: <std-proposals+bncBD7LHGWIQEPRB3EC7WJAKGQECTBGT5I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f199.google.com ([209.85.214.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD7LHGWIQEPRB3EC7WJAKGQECTBGT5I@isocpp.org>)
	id 1VWcfO-0001oJ-Np
	for gclcip-std-proposals@m.gmane.org; Thu, 17 Oct 2013 03:46:23 +0200
Original-Received: by mail-ob0-f199.google.com with SMTP id vb8sf4607518obc.6
        for <gclcip-std-proposals@m.gmane.org>; Wed, 16 Oct 2013 18:46:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe:content-type;
        bh=hJ5rjSXplTvlHdGU7bU+u1ZKhJKsodwTzN5wPrft6NY=;
        b=rLd/tb8+N28VvRDMF/O04vn6BP+esT5IG6rDgcDjT0Zs61w+doevW+dYkV5rL80SqJ
         xDok2RF6WMeqgCxbCI95KoBbjY5Or+IFHUzKr26x9iyN2G8GhOtksre4yKNw+9hCMmsC
         Hx7uFlAjYr8RaWNV+m72dgaw45jnv/6JJOxHa3KelIAwOCUTykOQcLIxNsJiuWtnKJ4/
         5Bch+6ywanH8x1J/BhshNgxsmVOxg3JurdaHnsVw+lCS0WCPCnR0pHZfTGMir+5k7h2q
         8PNaGMsr5vKRJEodHjK/IipbpuykXHIxSNcd2inFxJvxezBXamkVyJtvI/b16wvWDBgB
         cmYQ==
X-Received: by 10.182.109.164 with SMTP id ht4mr2159797obb.16.1381974381734;
        Wed, 16 Oct 2013 18:46:21 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.107.38 with SMTP id gz6ls3574134igb.2.canary; Wed, 16 Oct
 2013 18:46:20 -0700 (PDT)
X-Received: by 10.50.9.33 with SMTP id w1mr158410iga.12.1381974380379;
        Wed, 16 Oct 2013 18:46:20 -0700 (PDT)
X-Original-Sender: jgottman6@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:7334
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/7334>

------=_Part_370_21974380.1381974378963
Content-Type: text/plain; charset=ISO-8859-1

A common use-case for std::ostringstream is to to do something like the 
following:

std::string foo() {
   std::ostringstream os;
   /// write values to os
   return os.str();
}

The method os.str() returns a string that is a copy of the collected state 
of the ostringstream.  It has to be, because it is possible to write more 
values to os later.  But in this function, it is not necessary to maintain 
the state of the ostringstream, since it is about to be destructed anyway.  
It would therefore be very nice to be able to return a version of 
ostringstream::str() that steals the guts of the ostringstream, using 
something like move semantics, and uses them to construct the returned 
string more efficiently than by a copy  Is this technically feasible?  

Joe Gottman

-- 

--- 
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_370_21974380.1381974378963
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">A common use-case for std::ostringstream is to to do somet=
hing like the following:<br><br><div class=3D"prettyprint" style=3D"backgro=
und-color: rgb(250, 250, 250); border-color: rgb(187, 187, 187); border-sty=
le: solid; border-width: 1px; word-wrap: break-word;"><code class=3D"pretty=
print"><div class=3D"subprettyprint"><span style=3D"color: #000;" class=3D"=
styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">::</span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">string</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> foo</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp;std</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">ostringstream os</span><span=
 style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp;</span><span s=
tyle=3D"color: #800;" class=3D"styled-by-prettify">/// write values to os</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &=
nbsp;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">retur=
n</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> os</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">str</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span></div></code></div><br>The method os.str() =
returns a string that is a copy of the collected state of the ostringstream=
..&nbsp; It has to be, because it is possible to write more values to os lat=
er.&nbsp; But in this function, it is not necessary to maintain the state o=
f the ostringstream, since it is about to be destructed anyway.&nbsp; It wo=
uld therefore be very nice to be able to return a version of ostringstream:=
:str() that steals the guts of the ostringstream, using something like move=
 semantics, and uses them to construct the returned string more efficiently=
 than by a copy&nbsp; Is this technically feasible?&nbsp; <br><br>Joe Gottm=
an<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_370_21974380.1381974378963--

.
