220 14902 <CALDL7dGdt_n=rvNQ+SOOvrekqHhehb=+KxZOZaF-zhuTRiqoUg@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Farid Mehrabi <farid.mehrabi@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Earlier creation of function return-value.
Date: Mon, 8 Dec 2014 21:31:49 +0330
Lines: 298
Approved: news@gmane.org
Message-ID: <CALDL7dGdt_n=rvNQ+SOOvrekqHhehb=+KxZOZaF-zhuTRiqoUg@mail.gmail.com>
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/alternative; boundary=f46d04389251abba580509b83923
X-Trace: ger.gmane.org 1418061742 18914 80.91.229.3 (8 Dec 2014 18:02:22 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 8 Dec 2014 18:02:22 +0000 (UTC)
To: std-proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBC27JR6ERAOBBJOPS6SAKGQEDQTKKTA@isocpp.org Mon Dec 08 19:02:16 2014
Return-path: <std-proposals+bncBC27JR6ERAOBBJOPS6SAKGQEDQTKKTA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ee0-f70.google.com ([74.125.83.70])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC27JR6ERAOBBJOPS6SAKGQEDQTKKTA@isocpp.org>)
	id 1Xy2dS-0002Zc-1A
	for gclcip-std-proposals@m.gmane.org; Mon, 08 Dec 2014 19:02:14 +0100
Original-Received: by mail-ee0-f70.google.com with SMTP id b57sf3103837eek.5
        for <gclcip-std-proposals@m.gmane.org>; Mon, 08 Dec 2014 10:02:13 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=oliiq616/L02d/kLw5o6Vau82zTWqLH9SelbV/71bNg=;
        b=kN2YhsfiRxfCWQGMH6H5k6yHKaWwkhR6rIa4IcAfhqBBi9r8n9tX4OfLWAIIORVJMX
         ADvb9RUiVkNiGNNzozKAJBVpRLwv1YfOUchbhMtDcFWavydBe9JZNV/uuTYk2nGi7LpD
         83zZDQHJROYzndHn++wTS00OZyylIFK6iPwNbrNDn0rvqfxoKHqvkppR1TDS5erk5tGh
         rEoTRq7jWqoBz63SGCK+EqMm8sVPu5dn5O3mE3I56Gcib3LOOA/ezANRighkEM5QHS7M
         q0va/8tdICFoeoZhjsE+7Ym6qKmkcKWPilU16DUX5we3vyVtREjdAEF8nPCrn3220Es2
         N/Mg==
X-Gm-Message-State: ALoCoQnjLuOHJyEYr/Uc5ObxoZBLuGBAZ8a1iwP4m/3cysNonOeW8TbDcT8uIMr0q9lSuH02hiRl
X-Received: by 10.180.24.35 with SMTP id r3mr3675309wif.0.1418061733666;
        Mon, 08 Dec 2014 10:02:13 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.14.99 with SMTP id o3ls632255wic.9.canary; Mon, 08 Dec
 2014 10:02:12 -0800 (PST)
X-Received: by 10.194.8.34 with SMTP id o2mr30853671wja.129.1418061732143;
        Mon, 08 Dec 2014 10:02:12 -0800 (PST)
Original-Received: from mail-wi0-x235.google.com (mail-wi0-x235.google.com. [2a00:1450:400c:c05::235])
        by mx.google.com with ESMTPS id za2si62690487wjc.44.2014.12.08.10.02.12
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Mon, 08 Dec 2014 10:02:12 -0800 (PST)
Received-SPF: pass (google.com: domain of farid.mehrabi@gmail.com designates 2a00:1450:400c:c05::235 as permitted sender) client-ip=2a00:1450:400c:c05::235;
Original-Received: by mail-wi0-f181.google.com with SMTP id r20so5601023wiv.2
        for <std-proposals@isocpp.org>; Mon, 08 Dec 2014 10:02:11 -0800 (PST)
X-Received: by 10.180.90.147 with SMTP id bw19mr25440480wib.69.1418061729739;
 Mon, 08 Dec 2014 10:02:09 -0800 (PST)
Original-Received: by 10.217.59.131 with HTTP; Mon, 8 Dec 2014 10:01:49 -0800 (PST)
In-Reply-To: <3c0ee2e3-8706-44b0-a3d2-985e494dd8ac@isocpp.org>
X-Original-Sender: farid.mehrabi@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of farid.mehrabi@gmail.com designates 2a00:1450:400c:c05::235 as
 permitted sender) smtp.mail=farid.mehrabi@gmail.com;       dkim=pass
 header.i=@gmail.com;       dmarc=pass (p=NONE dis=NONE) header.from=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: <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:14902
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/14902>

--f46d04389251abba580509b83923
Content-Type: text/plain; charset=UTF-8

Sorry fo overmuch frankness, but regarding your other posts, IMHO u better
collect more info about "rvalue ref", "perfect forwarding", "std::move",
"copy ellision", "RVO" & "NRVO". I don`t think there exists any practical
motivation for this kind of syntax proposals today. 10 years ago they might.

cheers,
FM.

2014-12-08 0:52 GMT+03:30 sasho648 <sasho648@mail.bg>:

> I thought it would be a good idea to implement a language solution of the
> return by value additional temporary creation which is optimized by
> most-compilers but - you know it's better to make their life easier and
> also fix the problem in those where the optimization isn't done at all.
> What I mean is this:
>
> struct SomeData { int a, int b, int c };
>
>
> SomeData FuncRetSomeData()
>
> {
>     SomeData tmp; //creation of additional unneeded temporary
>
>
>
>     //store some data in 'tmp'
>
>
>
>     return tmp; //now second return object is created in the calling
> stack with data copied from 'tmp'
>
> }
>
>
> Most compilers will optimize this code and never create the local 'tmp'
> but instead store the data supposed to be held in it, directly in the
> return temporary. I suggest creating an old-code compatible new syntax for
> allowing similar behavior to be done explicitly by using '(return)' as an
> alias to the return value temporary which will be created at function
> beginning. Also an initialization syntax for the '(return)' will be
> supported like when initializing a class members (if it was named
> 'return'). This new syntax will be supported only when used, otherwise
> 'return' statements will be the ones which will create the return value. So
> the function "FuncRetSomeData" can be now written optimized like:
>
> struct SomeData { int a, int b, int c };
>
>
> SomeData FuncRetSomeData()
>
> {
>
>     //store some data in '(return)', like
>
>
>     (return).a = 0;
>
>
>     (return).b = 3; //etc.
>
>
>     return; //only return statement with no value will be supported to
> exit the function
>
> }
>
>
> '(return)' variable could be also initialized like class members. Example:
>
> struct SomeData { int a, int b, int c };
>
>
> SomeData FuncRetSomeData(int a, int b, int c) : return { a, b, c } {}
>
>
> Old code will be supported too:
>
> SomeData &FuncReturningRef()
> {
>     //Do Something and never use '(return)'
>
>
>
>     return ref; //if 'ref' is from type 'SomeData', the return value will
> be created now and the function will return (note if the '(return)' was
> used above - this statement would be illegal)
>
> }
>
>  --
>
> ---
> 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/.
>



-- 
how am I supposed to end the twisted road of  your hair in the dark night??
unless the candle of your face does turn a lamp up on my way!!!

-- 

--- 
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/.

--f46d04389251abba580509b83923
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"rtl"><div dir=3D"ltr">Sorry fo overmuch frankness, but regardin=
g your other posts, IMHO u better collect more info about &quot;rvalue ref&=
quot;, &quot;perfect forwarding&quot;, &quot;std::move&quot;, &quot;copy el=
lision&quot;, &quot;RVO&quot; &amp; &quot;NRVO&quot;. I don`t think there e=
xists any practical motivation for this kind of syntax proposals today. 10 =
years ago they might.</div><div dir=3D"ltr"><br></div><div dir=3D"ltr">chee=
rs,</div><div dir=3D"ltr">FM.</div></div><div class=3D"gmail_extra"><br><di=
v class=3D"gmail_quote"><div dir=3D"ltr">2014-12-08 0:52 GMT+03:30 sasho648=
 <span dir=3D"ltr">&lt;<a href=3D"mailto:sasho648@mail.bg" target=3D"_blank=
">sasho648@mail.bg</a>&gt;</span>:</div><blockquote class=3D"gmail_quote" s=
tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div=
 dir=3D"ltr">I thought it would be a good idea to implement a language solu=
tion of the return by value additional temporary creation which is optimize=
d by most-compilers but - you know it&#39;s better to make their life easie=
r and also fix the problem in those where the optimization isn&#39;t done a=
t all. What I mean is this:<br><br><div style=3D"border:1px solid rgb(187,1=
87,187);word-wrap:break-word;background-color:rgb(250,250,250)"><code><div>=
<span style=3D"color:#008">struct</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#606">SomeData</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"> </span><sp=
an style=3D"color:#008">int</span><span style=3D"color:#000"> a</span><span=
 style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#008">int</span><span style=3D"color:#000"> b</span><span style=
=3D"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#008">int</span><span style=3D"color:#000"> c </span><span style=3D"co=
lor:#660">};</span><span style=3D"color:#000"><br><br><br></span><span styl=
e=3D"color:#606">SomeData</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#606">FuncRetSomeData</span><span style=3D"color:#660">()</spa=
n><span style=3D"color:#000"><br><br></span><span style=3D"color:#660">{</s=
pan><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r:#606">SomeData</span><span style=3D"color:#000"> tmp</span><span style=3D=
"color:#660">;</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#800">//creation of additional unneeded temporary</span><span style=3D"co=
lor:#000"><br><br><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#800">/=
/store some data in &#39;tmp&#39;</span><span style=3D"color:#000"><br><br>=
<br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span><span =
style=3D"color:#000"> tmp</span><span style=3D"color:#660">;</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#800">//now second return o=
bject is created in the calling stack with data copied from &#39;tmp&#39;</=
span><span style=3D"color:#000"><br><br></span><span style=3D"color:#660">}=
</span></div></code></div><div><br></div><div><br></div><div>Most compilers=
 will optimize this code and never create the local &#39;tmp&#39; but inste=
ad store the data supposed to be held in it, directly in the return tempora=
ry. I suggest creating an old-code compatible new syntax for allowing simil=
ar behavior to be done explicitly by using &#39;(return)&#39; as an alias t=
o the return value temporary which will be created at function beginning. A=
lso an initialization syntax for the &#39;(return)&#39; will be supported l=
ike when initializing a class members (if it was named &#39;return&#39;).=
=C2=A0This new syntax will be supported only when used, otherwise &#39;retu=
rn&#39; statements will be the ones which will create the return value. So =
the function &quot;<span style=3D"color:rgb(102,0,102);font-family:monospac=
e;background-color:rgb(250,250,250)">FuncRetSomeData</span>&quot; can be no=
w written optimized like:</div><div><br><span style=3D"font-family:monospac=
e;color:rgb(0,0,136);background-color:rgb(250,250,250)"></span></div><div s=
tyle=3D"border:1px solid rgb(187,187,187);word-wrap:break-word;background-c=
olor:rgb(250,250,250)"><code><div><span style=3D"color:#008">struct</span><=
span style=3D"color:#000"> </span><span style=3D"color:#606">SomeData</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">{</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#008">int</span><span s=
tyle=3D"color:#000"> a</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#008">int</span><span style=3D=
"color:#000"> b</span><span style=3D"color:#660">,</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#008">int</span><span style=3D"color:=
#000"> c </span><span style=3D"color:#660">};</span><span style=3D"color:#0=
00"><br><br><br></span><span style=3D"color:#606">SomeData</span><span styl=
e=3D"color:#000"> </span><span style=3D"color:#606">FuncRetSomeData</span><=
span style=3D"color:#660">()</span><span style=3D"color:#000"><br><br></spa=
n><span style=3D"color:#660">{</span><span style=3D"color:#000"><br><br>=C2=
=A0 =C2=A0 </span><span style=3D"color:#800">//store some data in &#39;(ret=
urn)&#39;, like</span><span style=3D"color:#000"><br><br><br>=C2=A0 =C2=A0 =
</span><span style=3D"color:#660">(</span><span style=3D"color:#008">return=
</span><span style=3D"color:#660">).</span><span style=3D"color:#000">a </s=
pan><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span=
><span style=3D"color:#066">0</span><span style=3D"color:#660">;</span><spa=
n style=3D"color:#000"><br><br><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r:#660">(</span><span style=3D"color:#008">return</span><span style=3D"colo=
r:#660">).</span><span style=3D"color:#000">b </span><span style=3D"color:#=
660">=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#066=
">3</span><span style=3D"color:#660">;</span><span style=3D"color:#000"> </=
span><span style=3D"color:#800">//etc.</span><span style=3D"color:#000"><br=
><br><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008">return</span><span=
 style=3D"color:#660">;</span><span style=3D"color:#000"> </span><span styl=
e=3D"color:#800">//only return statement with no value will be supported to=
 exit the function</span><span style=3D"color:#000"><br><br></span><span st=
yle=3D"color:#660">}</span></div></code></div><div><span style=3D"font-fami=
ly:monospace;color:rgb(102,102,0);background-color:rgb(250,250,250)"><br></=
span></div><div><span style=3D"font-family:monospace;color:rgb(102,102,0);b=
ackground-color:rgb(250,250,250)"><br></span></div><div><span style=3D"back=
ground-color:rgb(250,250,250)"><span style=3D"color:rgb(34,34,34);font-fami=
ly:Arial,Helvetica,sans-serif;background-color:rgb(255,255,255)">&#39;(retu=
rn)&#39; variable could be also=C2=A0</span>initialized like class members.=
 Example:<br><br><div style=3D"border:1px solid rgb(187,187,187);word-wrap:=
break-word;background-color:rgb(250,250,250)"><code><div><span style=3D"col=
or:#008">struct</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#606">SomeData</span><span style=3D"color:#000"> </span><span style=3D"c=
olor:#660">{</span><span style=3D"color:#000"> </span><span style=3D"color:=
#008">int</span><span style=3D"color:#000"> a</span><span style=3D"color:#6=
60">,</span><span style=3D"color:#000"> </span><span style=3D"color:#008">i=
nt</span><span style=3D"color:#000"> b</span><span style=3D"color:#660">,</=
span><span style=3D"color:#000"> </span><span style=3D"color:#008">int</spa=
n><span style=3D"color:#000"> c </span><span style=3D"color:#660">};</span>=
<span style=3D"color:#000"><br><br><br></span><span style=3D"color:#606">So=
meData</span><span style=3D"color:#000"> </span><span style=3D"color:#606">=
FuncRetSomeData</span><span style=3D"color:#660">(</span><span style=3D"col=
or:#008">int</span><span style=3D"color:#000"> a</span><span style=3D"color=
:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#008=
">int</span><span style=3D"color:#000"> b</span><span style=3D"color:#660">=
,</span><span style=3D"color:#000"> </span><span style=3D"color:#008">int</=
span><span style=3D"color:#000"> c</span><span style=3D"color:#660">)</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">:</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#008">return</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#660">{</span><span sty=
le=3D"color:#000"> a</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> b</span><span style=3D"color:#660">,</span><span style=3D"=
color:#000"> c </span><span style=3D"color:#660">}</span><span style=3D"col=
or:#000"> </span><span style=3D"color:#660">{}</span><span style=3D"color:#=
000"><br><br></span></div></code></div><br></span>Old code will be supporte=
d too:<br><br></div><div style=3D"border:1px solid rgb(187,187,187);word-wr=
ap:break-word;background-color:rgb(250,250,250)"><code><div><span style=3D"=
color:#606">SomeData</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">&amp;</span><span style=3D"color:#606">FuncReturningRef</sp=
an><span style=3D"color:#660">()</span><span style=3D"color:#000"> <br></sp=
an><span style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0=
 =C2=A0 </span><span style=3D"color:#800">//Do Something and never use &#39=
;(return)&#39;</span><span style=3D"color:#000"><br><br><br><br>=C2=A0 =C2=
=A0 </span><span style=3D"color:#008">return</span><span style=3D"color:#00=
0"> </span><span style=3D"color:#008">ref</span><span style=3D"color:#660">=
;</span><span style=3D"color:#000"> </span><span style=3D"color:#800">//if =
&#39;ref&#39; is from type &#39;SomeData&#39;, the return value will be cre=
ated now and the function will return (note if the &#39;(return)&#39; was u=
sed above - this statement would be illegal)</span><span style=3D"color:#00=
0"><br><br></span><span style=3D"color:#660">}</span></div></code></div><sp=
an class=3D"HOEnZb"><font color=3D"#888888"><div><br></div></font></span></=
div><span class=3D"HOEnZb"><font color=3D"#888888">

<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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">std-proposals@isocpp.org</a>.<br>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</font></span></blockquote></div><br><br clear=3D"all"><div><br></div>-- <b=
r><div class=3D"gmail_signature"><div dir=3D"ltr">how am I supposed to end =
the twisted road of=C2=A0 your hair in the dark night??<br>unless the candl=
e of your face does turn a lamp up on my way!!!<br></div></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 />

--f46d04389251abba580509b83923--

.
