220 11299 <92baab38-23fd-46f3-9e68-b894c9a0f07b@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: =?UTF-8?Q?Andrzej_Krzemie=C5=84ski?= <akrzemi1@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: return type sugar (orthogonal to auto foo() {} )
Date: Fri, 13 Jun 2014 09:25:37 -0700 (PDT)
Lines: 134
Approved: news@gmane.org
Message-ID: <92baab38-23fd-46f3-9e68-b894c9a0f07b@isocpp.org>
References: <30a83c0d-00e6-462a-822e-a1789787ec05@isocpp.org>
 <1cf79c47-8a07-4e41-b96b-465b01e044fa@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_297_30792517.1402676738095"
X-Trace: ger.gmane.org 1402676752 22549 80.91.229.3 (13 Jun 2014 16:25:52 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 13 Jun 2014 16:25:52 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDT2DGOJ34DBBA6M5SOAKGQEPZEKAPQ@isocpp.org Fri Jun 13 18:25:44 2014
Return-path: <std-proposals+bncBDT2DGOJ34DBBA6M5SOAKGQEPZEKAPQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qc0-f199.google.com ([209.85.216.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDT2DGOJ34DBBA6M5SOAKGQEPZEKAPQ@isocpp.org>)
	id 1WvUIP-0007qi-0i
	for gclcip-std-proposals@m.gmane.org; Fri, 13 Jun 2014 18:25:41 +0200
Original-Received: by mail-qc0-f199.google.com with SMTP id l6sf1575472qcy.6
        for <gclcip-std-proposals@m.gmane.org>; Fri, 13 Jun 2014 09:25:40 -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=TLGX4iWdB8da1XeDpxsykPiAj1CFigiOFRrLUxuaiAE=;
        b=oPOMZBjpUzBoSoIzuGIC2SDcMg54jJGhwieZhD3NqPJgLevE9X8sYn8SPfxs4fgUEd
         650lzZmsg2JBS86aYWn0jHoHFuLeZ8Yzt61jNDtRc/MhF/CHVRFASXlFkForSeoqZiVI
         wO384d3csXfNz6e9VoTQ7tNbbrerB9p8S29+9fuCnniFOs6QxSTrDN2DYQ+Prx8G3YUQ
         MGM/gbivrjDd+28g8Hfrsfru4Ef7uUn1gzPmzoweARpFCJcm7Fmt05bBGAGR8PMlGlV8
         eeYgRH5b9mZoDiHbLt8KYnU8YX5F5sCFoTCPdP0zxfvWGhU+RmNh/atiXJaqSP1twml/
         tW/g==
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=TLGX4iWdB8da1XeDpxsykPiAj1CFigiOFRrLUxuaiAE=;
        b=ZhyJpx5qdfHX7CMBZ+nAF3t/PFqMzUJRMhQJsQihu8J9vxvaP6b58Gt5guwmQeHvAV
         ytsjoAL/3n4r168updEZKWBimEek2w92SN7okFvSGrkxofSivvfQBCZjnbbDBPL/lFsG
         cP28m1kSAvWhRf3EpBabpK4h965ctK4dU1kmAGXa2tPEcv5HCWTfuJKu2VyVRSRNuZGe
         s2HutUB+neJTvOolYrwdb6kXTlsJ5vS5zXpCDybJV6AyCX7ut6tjReYjm71vmD9KLNq7
         HK9owdYECKd1ReqpL+3JzdT+xOf2hNl6aHITUW5KWjn5+NYJz8KEPDGQinDCK558/C0I
         Ni5A==
X-Gm-Message-State: ALoCoQkcyi8cs5VrPH1XFOIHCQ5GOiEFWkorJFSpVXaKCiQ0RTPoH8ATYQ+PtDsUYY997R3v0XdW
X-Received: by 10.58.151.201 with SMTP id us9mr511785veb.23.1402676740213;
        Fri, 13 Jun 2014 09:25:40 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.87.38 with SMTP id q35ls1014650qgd.98.gmail; Fri, 13 Jun
 2014 09:25:39 -0700 (PDT)
X-Received: by 10.140.44.75 with SMTP id f69mr50899qga.11.1402676739413;
        Fri, 13 Jun 2014 09:25:39 -0700 (PDT)
In-Reply-To: <1cf79c47-8a07-4e41-b96b-465b01e044fa@isocpp.org>
X-Original-Sender: akrzemi1@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:11299
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11299>

------=_Part_297_30792517.1402676738095
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


W dniu pi=C4=85tek, 13 czerwca 2014 18:24:28 UTC+2 u=C5=BCytkownik Andrzej=
=20
Krzemie=C5=84ski napisa=C5=82:
>
>
> W dniu czwartek, 12 czerwca 2014 12:16:04 UTC+2 u=C5=BCytkownik walter123=
4=20
> napisa=C5=82:
>>
>> Coming back to C++ from Rust, one thing begin to miss is the 2way type=
=20
>> inference: its a nice choice on their part, you write the types in the=
=20
>> signature, then the types in the body are inferred.
>>
>> But perhaps a significant amount of this use could be covered by having=
=20
>> sugar to access the declared return type of a function within its own bo=
dy.
>>
>> imagine
>>
>> auto foo(  args...  )->decltype(....some expression based on args...) {
>>
>>       return_type  accumulator;     // 'return_type' is a shortcut for=
=20
>> whatever this functions declared return type is..
>>       ... do stuff with accumulator...
>>
>>      return accumulator.
>> }
>>
>> ways of doing that without a new keyword, perhaps 'decltype(return)' ,=
=20
>> any other ideas..
>> In some ways this would go beyond what rust currently does. (rust can't=
=20
>> yet use an expression for the return type, although making it generic of=
ten=20
>> works because of how the return types are inferred by callers)
>>
> =20
> How about doing it the Go style:
> =20
> auto foo(  args...  ) -> decltype(....some expression based on args...)=
=20
> accumulator
> {  =20
>   do_stuff_with(accumulator);
>   return accumulator.
> }
>
=20
Or even w/o return statement because it is obvious what we return:
=20
auto foo( args... ) -> decltype(....some expression based on args...)=20
accumulator
{=20
   do_stuff_with(accumulator);
   // no return (and no UB)
}

--=20

---=20
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 e=
mail 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-proposa=
ls/.

------=_Part_297_30792517.1402676738095
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br>W dniu pi=C4=85tek, 13 czerwca 2014 18:24:28 UTC+2 u=
=C5=BCytkownik Andrzej Krzemie=C5=84ski napisa=C5=82:<blockquote style=3D"m=
argin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 20=
4, 204); border-left-width: 1px; border-left-style: solid;" class=3D"gmail_=
quote"><div dir=3D"ltr"><br>W dniu czwartek, 12 czerwca 2014 12:16:04 UTC+2=
 u=C5=BCytkownik walter1234 napisa=C5=82:<blockquote style=3D"margin: 0px 0=
px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); bor=
der-left-width: 1px; border-left-style: solid;" class=3D"gmail_quote"><div =
dir=3D"ltr">Coming back to C++ from Rust, one thing begin to miss is the 2w=
ay type inference: its a nice choice on their part, you write the types in =
the signature, then the types in the body are inferred.<div><br></div><div>=
But perhaps a significant amount of this use could be covered by having sug=
ar to access the declared return type of a function within its own body.</d=
iv><div><br></div><div>imagine</div><div><br></div><div>auto foo( &nbsp;arg=
s... &nbsp;)-&gt;decltype(....some expression based on args...) {</div><div=
><br></div><div>&nbsp; &nbsp; &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 accumulat=
or...</div><div><br></div><div>&nbsp; &nbsp; &nbsp;return accumulator.</div=
><div>}</div><div><br></div><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, although making it generic often works because of how=
 the return types are inferred by callers)</div></div></blockquote><div>&nb=
sp;</div><div>How about doing it the Go style:</div><div>&nbsp;</div><div>a=
uto foo(&nbsp; args...&nbsp; ) -&gt; decltype(....some expression based on =
args...) accumulator<br>{&nbsp;&nbsp;&nbsp;<br>&nbsp; do_stuff_with(accumul=
ator);<br>&nbsp; return accumulator.<br>}</div></div></blockquote><div>&nbs=
p;</div><div>Or even w/o return statement because it is obvious what we ret=
urn:</div><div>&nbsp;</div><div>auto foo(  args...  ) -&gt; decltype(....so=
me expression based on args...) accumulator<br>{   <br> &nbsp;&nbsp; do_stu=
ff_with(accumulator);<br>&nbsp;&nbsp;&nbsp;// no return (and no UB)<br>}</d=
iv></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_297_30792517.1402676738095--

.
