220 14925 <356c4eaa-6d79-4938-869b-b3f8627cfa32@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: sasho648 <sasho648@mail.bg>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Earlier creation of function return-value.
Date: Tue, 9 Dec 2014 14:45:23 -0800 (PST)
Lines: 367
Approved: news@gmane.org
Message-ID: <356c4eaa-6d79-4938-869b-b3f8627cfa32@isocpp.org>
References: <3c0ee2e3-8706-44b0-a3d2-985e494dd8ac@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_5717_1363659495.1418165124119"
X-Trace: ger.gmane.org 1418165132 22829 80.91.229.3 (9 Dec 2014 22:45:32 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 9 Dec 2014 22:45:32 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDBNZXHN2QPRBBHXTWSAKGQEROQZF4Q@isocpp.org Tue Dec 09 23:45:27 2014
Return-path: <std-proposals+bncBDBNZXHN2QPRBBHXTWSAKGQEROQZF4Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pd0-f198.google.com ([209.85.192.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDBNZXHN2QPRBBHXTWSAKGQEROQZF4Q@isocpp.org>)
	id 1XyTX4-0005Yr-19
	for gclcip-std-proposals@m.gmane.org; Tue, 09 Dec 2014 23:45:26 +0100
Original-Received: by mail-pd0-f198.google.com with SMTP id fp1sf8247338pdb.9
        for <gclcip-std-proposals@m.gmane.org>; Tue, 09 Dec 2014 14:45:25 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:content-type:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=+xa8swto3OxBCBP/TUaVXtX9CI9lGFqBCRM6v35AYAQ=;
        b=TIo/mDo87F3iq7rcK2ZAPz3r3oKf9fF2GDHtRvZDZdhaQng8eeYhuX21R8CwuX/ndT
         oALzXwSc5diHGLoKwM9FEJR7MQx1cosVud56mTgMGJ7TiYiqGRJwrPf87fdn36wIW0HU
         VQl5d+9hDXG0rfDjgVoFKAqlgcHIMDWvl5TVctwjE2YsWp3f9FkjeKJjnoZDEp9nZ6XT
         swGKb4xmOYptOssr7Jh6l8OcZUUzUDuZ/O+c2/E9+n3KS0gXyU8V4KDTFQTYrF9KE2lX
         U6RapMapbPnl9D7WqH6Sn7wl12sOaDzOda/3RlVuH+g1FPP6NUlfSEXIrkDLHaIigd0m
         HCTg==
X-Gm-Message-State: ALoCoQnqcp+dSA5bRgbqa3OuwnQtwnkGcZMT1ESUw8qrfmijCzy3CYjCZLHmM2Tbv2eC/ak3KXKu
X-Received: by 10.66.248.229 with SMTP id yp5mr950553pac.12.1418165125291;
        Tue, 09 Dec 2014 14:45:25 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.105.202 with SMTP id c68ls359632qgf.62.gmail; Tue, 09 Dec
 2014 14:45:24 -0800 (PST)
X-Received: by 10.140.18.178 with SMTP id 47mr12503qgf.9.1418165124528;
        Tue, 09 Dec 2014 14:45:24 -0800 (PST)
In-Reply-To: <3c0ee2e3-8706-44b0-a3d2-985e494dd8ac@isocpp.org>
X-Original-Sender: sasho648@mail.bg
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: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:14925
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/14925>

------=_Part_5717_1363659495.1418165124119
Content-Type: multipart/alternative; 
	boundary="----=_Part_5718_1079651681.1418165124120"

------=_Part_5718_1079651681.1418165124120
Content-Type: text/plain; charset=UTF-8

What about - when we don't know exactly what local will be returned? In 
this case (at least my GCC compiler, even with '-02') haven't implemented 
any 'RVO'. By using a named variable which represents the return value, we 
can store one of those temporaries directly into it and in one of the cases 
no copying will be performed. Here is what I mean:

struct S
{
    S () { pSomeMemory = new char[250], cout << "S::S()" << endl; }

    S (const S &arg) : S() { memcpy(pSomeMemory, arg.pSomeMemory, sizeof(
char) * 250), cout << "S::S(const S &arg)" << endl; }

    S (S &&arg) : S() { pSomeMemory = arg.pSomeMemory, arg.pSomeMemory = 
nullptr, cout << "S::S(S &&arg)" << endl; }

    ~S () { delete[] pSomeMemory; }

    char *pSomeMemory;
};


S FunctionReturningS(bool b)
{
    //the below 2 temporaries must be constructed

    S temp;

    S temp1;

    //store some data at 'temp' and 'temp1'

    temp.pSomeMemory[0] = '\0';

    temp1.pSomeMemory[5] = '6';

    return (b ? (S&&)temp : (S&&)temp1); // return either 'temp' or 'temp1'
}

Life example <http://coliru.stacked-crooked.com/a/70566400ba29bac4>.

Using my new syntax we can optimize 'FunctionReturningS' like this:

S FunctionReturningS(bool b) return
{
    //the below 1 temporarie + 'return' must be constructed

    S temp;

    //store some data at 'temp' and 'return'

    temp.pSomeMemory[0] = '\0';

    return.pSomeMemory[5] = '6';

    if(!b) return; //just exit the function (temp1 is replaced by 'return')

    return.~return(); //calling explicit destructor on 'return'

    new (&return) S((&&)temp); //placement new, re-constructs 'return' by 
'temp'
}

As in my case if 'b' is 'false' no copy-construction will be done.

-- 

--- 
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_5718_1079651681.1418165124120
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">What about - when we don't know exactly what local will be=
 returned? In this case (at least my GCC compiler, even with '-02') haven't=
 implemented any 'RVO'. By using a named variable which represents the retu=
rn value, we can store one of those temporaries directly into it and in one=
 of the cases no copying will be performed. Here is what I mean:<br><br><di=
v class=3D"prettyprint" style=3D"border: 1px solid rgb(187, 187, 187); word=
-wrap: break-word; background-color: rgb(250, 250, 250);"><code class=3D"pr=
ettyprint"><div class=3D"subprettyprint"><span style=3D"color: #008;" class=
=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> S<br></span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br>&nbsp; &nbsp; S </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> pSomeMem=
ory </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">new</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">char</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">[</span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">250</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">],</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> cout </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">"S::S(=
)"</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> endl</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; S </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> S </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">arg</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> S</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"colo=
r: #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"> memcpy</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify">pSomeMemory</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
> arg</span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">pSomeMemory</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">sizeof</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">char</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">*</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #066;" class=3D"styled-by-prettify">250</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">),</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> cout </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #080;" class=3D"styled-by-prettify">"S::S(const S &amp;arg)"</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&lt;&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> endl</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">}</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br><br>&nbsp; &nbsp; S </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">S </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">&amp;&amp;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">arg</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
)</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> S</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">()</span><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"style=
d-by-prettify"> pSomeMemory </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"> arg</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">pSom=
eMemory</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> arg</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">pSomeMemory </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">nullptr</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> cout </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styled-by-p=
rettify">"S::S(S &amp;&amp;arg)"</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&lt;&lt;</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> endl</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbs=
p; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">~</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">S </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">()</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styl=
ed-by-prettify">delete</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">[]</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> pSomeMemory</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp;=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">char</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">*</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">pSomeMemory</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br><br><br>S </span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">FunctionReturningS</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">bool</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> b</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">{</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nb=
sp; </span><span style=3D"color: #800;" class=3D"styled-by-prettify">//the =
below 2 temporaries must be constructed</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; S temp</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; S temp1</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </spa=
n><span style=3D"color: #800;" class=3D"styled-by-prettify">//store some da=
ta at 'temp' and 'temp1'</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"><br><br>&nbsp; &nbsp; temp</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">pSomeMemory</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">[</span><span style=3D"color: #066;" class=3D"style=
d-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">]</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #080;" class=3D"styled-by-prettify">'\0'</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; temp1</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">pSomeMemory</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">5</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">]</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">'6'</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">b </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">?</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">&nbsp;</span><span style=3D"color: rgb(0, 0, 0); fo=
nt-family: Arial, Helvetica, sans-serif;">(S&amp;&amp;)</span><span class=
=3D"styled-by-prettify" style=3D"font-family: Arial, Helvetica, sans-serif;=
 color: rgb(0, 0, 0);">temp </span><span class=3D"styled-by-prettify" style=
=3D"font-family: Arial, Helvetica, sans-serif; color: rgb(102, 102, 0);">:<=
/span><span class=3D"styled-by-prettify" style=3D"font-family: Arial, Helve=
tica, sans-serif; color: rgb(0, 0, 0);">&nbsp;</span><span style=3D"color: =
rgb(0, 0, 0); font-family: Arial, Helvetica, sans-serif;">(S&amp;&amp;)</sp=
an><span class=3D"styled-by-prettify" style=3D"font-family: Arial, Helvetic=
a, sans-serif; color: rgb(0, 0, 0);">temp1</span><span class=3D"styled-by-p=
rettify" style=3D"font-family: Arial, Helvetica, sans-serif; color: rgb(102=
, 102, 0);">);</span><span class=3D"styled-by-prettify" style=3D"font-famil=
y: Arial, Helvetica, sans-serif; color: rgb(0, 0, 0);"> </span><span class=
=3D"styled-by-prettify" style=3D"font-family: Arial, Helvetica, sans-serif;=
 color: rgb(136, 0, 0);">// return either 'temp' or 'temp1'</span></div><di=
v class=3D"subprettyprint"><span style=3D"color: #660;" class=3D"styled-by-=
prettify">}</span></div></code></div><div><br>Life <a href=3D"http://coliru=
..stacked-crooked.com/a/70566400ba29bac4">example</a>.</div><div><br></div><=
div>Using my new syntax we can optimize '<span style=3D"color: rgb(102, 0, =
102); font-family: monospace; background-color: rgb(250, 250, 250);">Functi=
onReturningS</span>' like this:</div><div><br><span class=3D"styled-by-pret=
tify" style=3D"font-family: monospace; color: rgb(0, 0, 0); background-colo=
r: rgb(250, 250, 250);"></span></div><div class=3D"prettyprint" style=3D"bo=
rder: 1px solid rgb(187, 187, 187); word-wrap: break-word; background-color=
: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"subprettyp=
rint"><span style=3D"color: #000;" class=3D"styled-by-prettify">S </span><s=
pan style=3D"color: #606;" class=3D"styled-by-prettify">FunctionReturningS<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">bool</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> b</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">return</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-prett=
ify"><br>&nbsp; &nbsp; </span><span style=3D"color: #800;" class=3D"styled-=
by-prettify">//the below 1 temporarie + 'return' must be constructed</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &n=
bsp; S temp</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=
&nbsp; &nbsp; </span><span style=3D"color: #800;" class=3D"styled-by-pretti=
fy">//store some data at 'temp' and 'return'</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; temp</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">.</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">pSomeMemory</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">[</span><span style=3D"color: #06=
6;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">]</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">'\0'</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">return</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify">pSomeMemory</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">[</span><span style=3D"co=
lor: #066;" class=3D"styled-by-prettify">5</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">]</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">'=
6'</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &n=
bsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">if</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(!</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">b</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" =
class=3D"styled-by-prettify">return</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #800;" class=3D"styled-by-pre=
ttify">//just exit the function (temp1 is replaced by 'return')</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">return</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">.~</span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #80=
0;" class=3D"styled-by-prettify">//calling explicit destructor on 'return'<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nb=
sp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>new</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">(&amp;</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">return</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">)</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> S</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">((&amp;&amp;)</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify">temp</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"style=
d-by-prettify">//placement new, re-constructs 'return' by 'temp'</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">}</span></div></code></div>=
<div><span class=3D"styled-by-prettify" style=3D"font-family: monospace; co=
lor: rgb(102, 102, 0); background-color: rgb(250, 250, 250);"><br></span>As=
 in my case if 'b' is 'false' no copy-construction will be done.</div></div=
>

<p></p>

-- <br />
<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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<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_5718_1079651681.1418165124120--
------=_Part_5717_1363659495.1418165124119--

.
