220 11278 <CAMeU-s1V+fTNv-EuK0-9m6aLoeBENO1bRMn89x3XnRQjjxy1GQ@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Mikhail Semenov <mikhailsemenov1957@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: return type sugar (orthogonal to auto foo() {} )
Date: Thu, 12 Jun 2014 16:03:03 +0100
Lines: 162
Approved: news@gmane.org
Message-ID: <CAMeU-s1V+fTNv-EuK0-9m6aLoeBENO1bRMn89x3XnRQjjxy1GQ@mail.gmail.com>
References: <30a83c0d-00e6-462a-822e-a1789787ec05@isocpp.org>
	<CAGdQazdTYTYvwt6gDqU5U2WBeHaU4G8-za85D6OQ+Lp+xpeq2w@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=047d7bfd01668f2e8404fba4db9f
X-Trace: ger.gmane.org 1402585396 11936 80.91.229.3 (12 Jun 2014 15:03:16 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 12 Jun 2014 15:03:16 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDC55PNFRYGRBKEC46OAKGQE7APSDSI@isocpp.org Thu Jun 12 17:03:08 2014
Return-path: <std-proposals+bncBDC55PNFRYGRBKEC46OAKGQE7APSDSI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lb0-f200.google.com ([209.85.217.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDC55PNFRYGRBKEC46OAKGQE7APSDSI@isocpp.org>)
	id 1Wv6Wv-0007mw-VW
	for gclcip-std-proposals@m.gmane.org; Thu, 12 Jun 2014 17:03:06 +0200
Original-Received: by mail-lb0-f200.google.com with SMTP id z11sf937921lbi.7
        for <gclcip-std-proposals@m.gmane.org>; Thu, 12 Jun 2014 08:03:05 -0700 (PDT)
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:date
         :message-id:subject:from:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=oUNJ+w7HNSPG4WJp2TtCZf3m2LdG93g99lJNtrGKOKY=;
        b=BLYHKe6b1kQlSnoTALF+uKsn6lyja4AppeaiPgXWUt4yoOWiGfvKBaM44c2x0kD6KI
         7VXTE6xHMq/RuMO/eqoWM6DQ8gYaCZ/Ql9c8GF+891dc2xTDktRyK/nr2yDW3Lu3SaES
         sV+I/Q3DIVcXNpSRfq9FCcLYE/33KLV/vHrcNa/rO9Q5cukT8GsOcX0PWLVjxtxSxIUf
         bK9u5vnmVldXhXfdS7O87SxMIUp5NfVKjPtCoTk6oNYJ/Dp0vmtOZzMdDkGgRiq6Q1bw
         MVZ4oCuaW4KMMXDYu7thVFYs97NTUXRf9Ft1TD4+UNT7lhlRmmrpqQ0Uuh2RDRPYEKYD
         +YBA==
X-Gm-Message-State: ALoCoQkjjbnX+m1A9OFFx3w5iZWddC0crMInY2/Rr5cSbXQJigmIcqAYkxPakv4UqrMd2PQ3+6BS
X-Received: by 10.112.14.5 with SMTP id l5mr5611583lbc.6.1402585385760;
        Thu, 12 Jun 2014 08:03:05 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.81.164 with SMTP id b4ls435653wiy.8.canary; Thu, 12 Jun
 2014 08:03:04 -0700 (PDT)
X-Received: by 10.180.211.36 with SMTP id mz4mr7540656wic.20.1402585384303;
        Thu, 12 Jun 2014 08:03:04 -0700 (PDT)
Original-Received: from mail-wi0-x22e.google.com (mail-wi0-x22e.google.com [2a00:1450:400c:c05::22e])
        by mx.google.com with ESMTPS id r4si3607951wiv.24.2014.06.12.08.03.04
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Thu, 12 Jun 2014 08:03:04 -0700 (PDT)
Received-SPF: pass (google.com: domain of mikhailsemenov1957@gmail.com designates 2a00:1450:400c:c05::22e as permitted sender) client-ip=2a00:1450:400c:c05::22e;
Original-Received: by mail-wi0-f174.google.com with SMTP id bs8so3621851wib.1
        for <std-proposals@isocpp.org>; Thu, 12 Jun 2014 08:03:03 -0700 (PDT)
X-Received: by 10.194.92.148 with SMTP id cm20mr6147110wjb.57.1402585383642;
 Thu, 12 Jun 2014 08:03:03 -0700 (PDT)
Original-Received: by 10.216.51.143 with HTTP; Thu, 12 Jun 2014 08:03:03 -0700 (PDT)
In-Reply-To: <CAGdQazdTYTYvwt6gDqU5U2WBeHaU4G8-za85D6OQ+Lp+xpeq2w@mail.gmail.com>
X-Original-Sender: mikhailsemenov1957@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of mikhailsemenov1957@gmail.com designates 2a00:1450:400c:c05::22e as
 permitted sender) smtp.mail=mikhailsemenov1957@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: <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:11278
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11278>

--047d7bfd01668f2e8404fba4db9f
Content-Type: text/plain; charset=UTF-8

You can already write:
auto foo(int x, double y)->decltype(x+y)
{
    ...
}


On 12 June 2014 15:10, Sebastian Gesemann <s.gesemann@gmail.com> wrote:

> On Thu, Jun 12, 2014 at 12:16 PM, 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)
>
> I'm not sure about the utility for such a short cut -- given the fact
> that in C++14 you can do something like this:
>
>   // note: no trailing return type
>   auto foo(int x, double y) {
>     return x+y;
>   }
>
> Compared to what you suggest, this is the other way around: The return
> type can be deduced from whatever the function returns.
>
> --
>
> ---
> 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/.
>

-- 

--- 
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/.

--047d7bfd01668f2e8404fba4db9f
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>You can already write:</div><div>auto foo(int x, doub=
le y)-&gt;decltype(x+y) </div><div>{<br>=C2=A0=C2=A0=C2=A0=C2=A0...<br>}<br=
></div></div><div class=3D"gmail_extra"><br><br><div class=3D"gmail_quote">=
On 12 June 2014 15:10, Sebastian Gesemann <span dir=3D"ltr">&lt;<a href=3D"=
mailto:s.gesemann@gmail.com" target=3D"_blank">s.gesemann@gmail.com</a>&gt;=
</span> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div>On Thu, Jun 12, 2014 at 12:16 PM, walte=
r1234 wrote:<br>
&gt; Coming back to C++ from Rust, one thing begin to miss is the 2way type=
<br>
&gt; inference: its a nice choice on their part, you write the types in the=
<br>
&gt; signature, then the types in the body are inferred.<br>
&gt;<br>
&gt; But perhaps a significant amount of this use could be covered by havin=
g<br>
&gt; sugar to access the declared return type of a function within its own =
body.<br>
&gt;<br>
&gt; imagine<br>
&gt;<br>
&gt; auto foo( =C2=A0args... =C2=A0)-&gt;decltype(....some expression based=
 on args...) {<br>
&gt;<br>
&gt; =C2=A0 =C2=A0 =C2=A0 return_type =C2=A0accumulator; =C2=A0 =C2=A0 // &=
#39;return_type&#39; is a shortcut for<br>
&gt; whatever this functions declared return type is..<br>
&gt; =C2=A0 =C2=A0 =C2=A0 ... do stuff with accumulator...<br>
&gt;<br>
&gt; =C2=A0 =C2=A0 =C2=A0return accumulator.<br>
&gt; }<br>
&gt;<br>
&gt; ways of doing that without a new keyword, perhaps &#39;decltype(return=
)&#39; , any<br>
&gt; other ideas..<br>
&gt; In some ways this would go beyond what rust currently does. (rust can&=
#39;t yet<br>
&gt; use an expression for the return type, although making it generic ofte=
n<br>
&gt; works because of how the return types are inferred by callers)<br>
<br>
</div>I&#39;m not sure about the utility for such a short cut -- given the =
fact<br>
that in C++14 you can do something like this:<br>
<br>
=C2=A0 // note: no trailing return type<br>
=C2=A0 auto foo(int x, double y) {<br>
=C2=A0 =C2=A0 return x+y;<br>
=C2=A0 }<br>
<br>
Compared to what you suggest, this is the other way around: The return<br>
type can be deduced from whatever the function returns.<br>
<div class=3D"HOEnZb"><div class=3D"h5"><br>
--<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%2Bunsubscribe@isocpp.org">std-propo=
sals+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/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br></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 />

--047d7bfd01668f2e8404fba4db9f--

.
