220 14951 <1dddd305-0b0d-47ff-b425-20ce1e1ff6e0@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: Wed, 10 Dec 2014 12:35:57 -0800 (PST)
Lines: 219
Approved: news@gmane.org
Message-ID: <1dddd305-0b0d-47ff-b425-20ce1e1ff6e0@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_863_1198208871.1418243757276"
X-Trace: ger.gmane.org 1418243768 7376 80.91.229.3 (10 Dec 2014 20:36:08 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 10 Dec 2014 20:36:08 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDBNZXHN2QPRBLO5UKSAKGQE7F37TNA@isocpp.org Wed Dec 10 21:36:00 2014
Return-path: <std-proposals+bncBDBNZXHN2QPRBLO5UKSAKGQE7F37TNA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ig0-f199.google.com ([209.85.213.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDBNZXHN2QPRBLO5UKSAKGQE7F37TNA@isocpp.org>)
	id 1XynzK-0002Ck-Uv
	for gclcip-std-proposals@m.gmane.org; Wed, 10 Dec 2014 21:35:59 +0100
Original-Received: by mail-ig0-f199.google.com with SMTP id hl2sf17356438igb.10
        for <gclcip-std-proposals@m.gmane.org>; Wed, 10 Dec 2014 12:35:58 -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=pcK/oHlESjmOb83mAfjyj4Om8NfVvUEtZkecuCcyE6U=;
        b=b4bAfPjhXfSq+N98kg1E/4I+2SAhZeUvKH5GVJvDTJ+pZDIfJF3hkMikyFEwfIY0Ee
         0QcNRnyV3lgALZ36tBdT4eRygzq5Jb5pOBdCCcs1gMza1NKvG1dTWQV2zWJztOVcALZ6
         LSPvtascTUoG7CQphHVyIw/oGHdgJ5x9fO8UCB1/JcL/qrWaQ9ditiOKH+zNZPuRWSwY
         3jc96NwO61g+wVRgeyrl9C8z3quMremwoJ9Ptvb1nyk3+1bUm4Zzz5y9B2A7H1wchmnz
         /NXcm3guImiAxAw2CfOaOH/2zgmpDhFrGZYZ9kpEIQabCiSo1lXY6buI3zZN/4bGsFK6
         e4HA==
X-Gm-Message-State: ALoCoQnbJTpddHnQnnzhIwkGjSu1yy9oQU4uNXBYdZ0NcGP4wqwaQr2nen+HAepNa39GSCnPbhNc
X-Received: by 10.182.65.232 with SMTP id a8mr5607149obt.5.1418243758355;
        Wed, 10 Dec 2014 12:35:58 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.94.209 with SMTP id g75ls787980qge.75.gmail; Wed, 10 Dec
 2014 12:35:57 -0800 (PST)
X-Received: by 10.140.94.150 with SMTP id g22mr134453qge.0.1418243757805;
        Wed, 10 Dec 2014 12:35:57 -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:14951
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/14951>

------=_Part_863_1198208871.1418243757276
Content-Type: multipart/alternative; 
	boundary="----=_Part_864_1342336978.1418243757276"

------=_Part_864_1342336978.1418243757276
Content-Type: text/plain; charset=UTF-8

Never mind. It seems I actually find a way to implement this without the 
need of introducing a new syntax by using class constructors like this:

struct FunctionReturningS
{
    explicit FunctionReturningS(bool b)
    {
        S temp;

        //store some data at 'temp' and 'return_value'

        temp.pSomeMemory[0] = '9';

        return_value.pSomeMemory[5] = '6';

        if(!b) return; //just exit the function (temp1 is replaced by 
'return_value')

        return_value.~S(); //calling explicit destructor on 'return_value'

        new (&return_value) S((S &&)temp); //placement new, re-constructs 
'return_value' by 'temp'
    }


    S return_value;
};

So you can instance the function like:

int main()
{
    auto &&RetValue = FunctionReturningS(true).return_value;

    cout << RetValue.pSomeMemory[0] << endl;

    auto &&RetValue1 = FunctionReturningS(false);

    return 0;
}


Thanks for your opinions anyway.

-- 

--- 
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_864_1342336978.1418243757276
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Never mind. It seems I actually find a way to implement th=
is without the need of introducing a new syntax by using class constructors=
 like this:<br><br><div class=3D"prettyprint" style=3D"border: 1px solid rg=
b(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, 25=
0);"><code class=3D"prettyprint"><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"> </span><span style=3D"color: #6=
06;" class=3D"styled-by-prettify">FunctionReturningS</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">explicit</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </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>&nbsp; &nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>&nbsp; &nbsp; &nbsp; &nbsp; S temp</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style=
=3D"color: #800;" class=3D"styled-by-prettify">//store some data at 'temp' =
and 'return_value'</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br><br>&nbsp; &nbsp; &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=
"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">]</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </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: #080;" class=3D"styled-by-prettify">'9'</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; &nbsp; &nbsp; r=
eturn_value</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">[</span=
><span style=3D"color: #066;" class=3D"styled-by-prettify">5</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">]</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"styl=
ed-by-prettify">'6'</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br><br>&nbsp; &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">if</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">(!</span><span 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><spa=
n 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"styled-by-prettify">//just exit the function (temp1 is re=
placed by 'return_value')</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br>&nbsp; &nbsp; &nbsp; &nbsp; return_value</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">();</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">//calling explicit destructor on 'return_value'</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp;=
 &nbsp; &nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">new</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">(&am=
p;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">return_v=
alue</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)</spa=
n><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=
"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_value' by 'temp'</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><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"><br><br><br>&nbs=
p; &nbsp; S return_value</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">}=
;</span></div></code></div><div><br></div><div>So you can instance the func=
tion like:<br><br><div 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"prettyprint"><div class=3D"subprettyprint"><span style=
=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> main</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">()</span><span style=3D"color: #000;" cl=
ass=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-b=
y-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&amp;&amp;</span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">RetValue</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </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: #606;" class=3D"styled-by-prettify">FunctionReturningS</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">true</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">).</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">return_value</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; cout </span><span sty=
le=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=
: #606;" class=3D"styled-by-prettify">RetValue</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify">pSomeMemory</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">[</span><span style=3D"color: #066;" class=3D"s=
tyled-by-prettify">0</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">&lt;&lt;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> endl</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;</span><span styl=
e=3D"color: #606;" class=3D"styled-by-prettify">RetValue1</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=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: #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">false</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">);</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</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #066;" 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"styled-by-prettify"><br></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span></div=
></code></div><div><br><br>Thanks for your opinions anyway.</div></div></di=
v>

<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_864_1342336978.1418243757276--
------=_Part_863_1198208871.1418243757276--

.
