220 11293 <2d5fa56c-d925-4b6b-90c8-b448e409058f@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: mitchnull@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: return type sugar (orthogonal to auto foo() {} )
Date: Fri, 13 Jun 2014 01:04:35 -0700 (PDT)
Lines: 141
Approved: news@gmane.org
Message-ID: <2d5fa56c-d925-4b6b-90c8-b448e409058f@isocpp.org>
References: <30a83c0d-00e6-462a-822e-a1789787ec05@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_214_29830601.1402646675584"
X-Trace: ger.gmane.org 1402646685 12819 80.91.229.3 (13 Jun 2014 08:04:45 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 13 Jun 2014 08:04:45 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBC36XNFZ4YKBBFHB5KOAKGQEEFCUFIA@isocpp.org Fri Jun 13 10:04:38 2014
Return-path: <std-proposals+bncBC36XNFZ4YKBBFHB5KOAKGQEEFCUFIA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vc0-f199.google.com ([209.85.220.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC36XNFZ4YKBBFHB5KOAKGQEEFCUFIA@isocpp.org>)
	id 1WvMTV-0001Vs-SJ
	for gclcip-std-proposals@m.gmane.org; Fri, 13 Jun 2014 10:04:38 +0200
Original-Received: by mail-vc0-f199.google.com with SMTP id ij19sf6440100vcb.6
        for <gclcip-std-proposals@m.gmane.org>; Fri, 13 Jun 2014 01:04:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references: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=kDizpSMeR+oTChQ2ShKoEXXmXoCDtHRLbVydPq6yBSs=;
        b=F1biZbHzsWb9SgNoImBNk7SzH3IRoXUml/Cr5ZApxORxCkFMdZ3jvSSmOl3cUN9+V+
         dMr5LfwKQVNq3lXXC1fJ/80iMwJkfIwf5qLFYSpdrypGV9ZzSEmbIiBX0vxHW4mmyUOh
         74QAvnV29lx42PIx3weZAVHQJucfpXBVUmWYGP3ivT1v0KA3lNIErVi0OXPQyXu2yCFa
         UdBJC5KEQu5t6nue/FSPlpoN2oNFRmxrsE4UwAwhn5auxJTzvz9Khgh8DtJMflUsJX40
         veB7GzBgeEh8uxL/Kw4Bjq5nf62VqxVJJy2PzMNLH6vdPSTmtt12XohafLlhTDG2DIXM
         /uCQ==
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:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=kDizpSMeR+oTChQ2ShKoEXXmXoCDtHRLbVydPq6yBSs=;
        b=lBqsiIXF97dz4XVFLzJzj0cdQ6dC+FtKUq6dQsJxSdar2O/1y+2LaoruklCOfT962z
         t0C5j6HLI/qhefFOTGN2vs/mXxPo3rLvrv61mhAfRlGi1IycXzQtPGKFbkVGQivEL3mv
         VKSkDWObASL29/gceK01/lsCdLjTCk3YbcYBZBkSsNJZqecDKkHfvQUTm0gycXeTBhHl
         KkNezYucAg7NpFNXGjyU+7IRM0lM8oBbyL9t52zuBCkBeo6ZxXhArSD6BbLdk8sGRw40
         MwcytQ+kbpJiJv0mArNapknalGXzVVq/get7+Dm2xL/Cm8z2NR6wJhhAXfJok0mcgJek
         1MoQ==
X-Gm-Message-State: ALoCoQmfPCSc/IwHoqs5/bSV58Y0AVlbl7v3t6PN0Ry8QUhRSmqeOtLShUKOB2Jj9V+xXhpnRNqk
X-Received: by 10.236.1.198 with SMTP id 46mr181047yhd.16.1402646676988;
        Fri, 13 Jun 2014 01:04:36 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.30.165 with SMTP id d34ls3400875qgd.25.gmail; Fri, 13 Jun
 2014 01:04:36 -0700 (PDT)
X-Received: by 10.140.93.23 with SMTP id c23mr16715qge.14.1402646676244;
        Fri, 13 Jun 2014 01:04:36 -0700 (PDT)
In-Reply-To: <30a83c0d-00e6-462a-822e-a1789787ec05@isocpp.org>
X-Original-Sender: mitchnull@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:11293
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11293>

------=_Part_214_29830601.1402646675584
Content-Type: text/plain; charset=UTF-8

How about:

auto foo(int bar, float baz) -> decltype(bar + baz) {
    decltype(foo(bar, baz)) res = bar + baz;
    return res;
}


this way you don't have to repeat the expression, you only need to change 
the type of "res" if the function name / parameters change.  Having 
decltype(return) be just syntax sugar for the above would be nice and easy 
to do, so I think it would be nice to have a proposal for this.


On Thursday, June 12, 2014 12:16:04 PM UTC+2, walter1234 wrote:
>
> Coming back to C++ from Rust, one thing begin to miss is the 2way type 
> inference: its a nice choice on their part, you write the types in the 
> signature, then the types in the body are inferred.
>
> But perhaps a significant amount of this use could be covered by having 
> sugar to access the declared return type of a function within its own body.
>
> imagine
>
> auto foo(  args...  )->decltype(....some expression based on args...) {
>
>       return_type  accumulator;     // 'return_type' is a shortcut for 
> whatever this functions declared return type is..
>       ... do stuff with accumulator...
>
>      return accumulator.
> }
>
> ways of doing that without a new keyword, perhaps 'decltype(return)' , any 
> other ideas..
> In some ways this would go beyond what rust currently does. (rust can't 
> yet use an expression for the return type, although making it generic often 
> works because of how the return types are inferred by callers)
>

-- 

--- 
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_214_29830601.1402646675584
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">How about:<div><br></div><div><div class=3D"prettyprint" s=
tyle=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; backgr=
ound-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div class=3D"=
subprettyprint"><span style=3D"color: #008;" class=3D"styled-by-prettify">a=
uto</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> foo</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span=
 style=3D"color: #008;" class=3D"styled-by-prettify">int</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> bar</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">float</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> baz</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">)</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">-&gt;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">decltype</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">bar </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">+</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> baz</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">decltype</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">foo<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify">bar</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> baz</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">))</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> res </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> bar </span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">+</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
baz</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: #008;" class=3D"styled-by-prettify">return</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> res</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"><br><br></span></div></code></div><div><br=
>this way you don't have to repeat the expression, you only need to change =
the type of "res" if the function name / parameters change. &nbsp;Having de=
cltype(return) be just syntax sugar for the above would be nice and easy to=
 do, so I think it would be nice to have a proposal for this.</div><div><br=
></div><br>On Thursday, June 12, 2014 12:16:04 PM UTC+2, walter1234 wrote:<=
blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;bord=
er-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">Coming back to=
 C++ from Rust, one thing begin to miss is the 2way type inference: its a n=
ice choice on their part, you write the types in the signature, then the ty=
pes in the body are inferred.<div><br></div><div>But perhaps a significant =
amount of this use could be covered by having sugar to access the declared =
return type of a function within its own body.</div><div><br></div><div>ima=
gine</div><div><br></div><div>auto foo( &nbsp;args... &nbsp;)-&gt;decltype(=
.....some expression based on args...) {</div><div><br></div><div>&nbsp; &nb=
sp; &nbsp; return_type &nbsp;accumulator; &nbsp; &nbsp; // 'return_type' is=
 a shortcut for whatever this functions declared return type is..</div><div=
>&nbsp; &nbsp; &nbsp; ... do stuff with accumulator...</div><div><br></div>=
<div>&nbsp; &nbsp; &nbsp;return accumulator.</div><div>}</div><div><br></di=
v><div>ways of doing that without a new keyword, perhaps 'decltype(return)'=
 , any other ideas..</div><div>In some ways this would go beyond what rust =
currently does. (rust can't yet use an expression for the return type, alth=
ough making it generic often works because of how the return types are infe=
rred by callers)</div></div></blockquote></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_214_29830601.1402646675584--

.
