220 11295 <CAD6_Qj854hGhx0KkznxKVCFOKRun3HKu0o2Swd52j6pH2+vn1A@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: =?UTF-8?Q?David_Rodr=C3=ADguez_Ibeas?= <dibeas@ieee.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: return type sugar (orthogonal to auto foo() {} )
Date: Fri, 13 Jun 2014 09:12:37 -0400
Lines: 102
Approved: news@gmane.org
Message-ID: <CAD6_Qj854hGhx0KkznxKVCFOKRun3HKu0o2Swd52j6pH2+vn1A@mail.gmail.com>
References: <30a83c0d-00e6-462a-822e-a1789787ec05@isocpp.org>
	<CAGdQazdTYTYvwt6gDqU5U2WBeHaU4G8-za85D6OQ+Lp+xpeq2w@mail.gmail.com>
	<fd784f28-1868-46d2-a211-8970b01388f9@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a113a2a2e7408f304fbb76e4e
X-Trace: ger.gmane.org 1402665166 3538 80.91.229.3 (13 Jun 2014 13:12:46 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Fri, 13 Jun 2014 13:12:46 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDIIVO6GQULBBRXR5OOAKGQE7D3QTJA@isocpp.org Fri Jun 13 15:12:40 2014
Return-path: <std-proposals+bncBDIIVO6GQULBBRXR5OOAKGQE7D3QTJA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qa0-f72.google.com ([209.85.216.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDIIVO6GQULBBRXR5OOAKGQE7D3QTJA@isocpp.org>)
	id 1WvRHb-0002eD-RW
	for gclcip-std-proposals@m.gmane.org; Fri, 13 Jun 2014 15:12:40 +0200
Original-Received: by mail-qa0-f72.google.com with SMTP id i13sf7575467qae.3
        for <gclcip-std-proposals@m.gmane.org>; Fri, 13 Jun 2014 06:12:39 -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:sender: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=LgO22+mdjc+jJZ5Nt34fDSsLkGl35wNjRrfZmcHdQyU=;
        b=iqh4GKjcvMSrKREflBqAGuqhvh6gbwah3Hcj0cUu7roB8l7ErbYipUJtPXA9rCMQj0
         CE8KUJnoZLtx3OFLEXlvFIxsxGGuOhOuFnc8EKmZgcWSlBbvP7mIw16PVDpZxvIaaURM
         NAyQMg68eQwFx5gUbIH186b2sFlAgnwyEYzNeYACvFnc6n2GD/xOcSRAvEB2CvGLKhfB
         VexhJ7h4xFI1k4VIoGZ+ABfh+cJTNobgUGc7rAgdXg1PGPFN1nxQ8WAYvrKNdj7MTDwN
         eZIqULMrrAJQ+q5V0o/mocW05aO+rqADQTZr/gLGHzV3e/1FZqogDm4kFuZ95xoxzyoC
         U3Fg==
X-Gm-Message-State: ALoCoQn82BGzIb3qtonkFI95tuwNnjWDy+5blBY+AcXjlklNIfzsI9oy/fELy4J/dPHGu3/spXrj
X-Received: by 10.58.48.233 with SMTP id p9mr540058ven.31.1402665159028;
        Fri, 13 Jun 2014 06:12:39 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.107.97 with SMTP id g88ls3298974qgf.40.gmail; Fri, 13 Jun
 2014 06:12:38 -0700 (PDT)
X-Received: by 10.224.38.4 with SMTP id z4mr3520860qad.94.1402665158078;
        Fri, 13 Jun 2014 06:12:38 -0700 (PDT)
Original-Received: from mail-qc0-x235.google.com (mail-qc0-x235.google.com [2607:f8b0:400d:c01::235])
        by mx.google.com with ESMTPS id c18si4546823qaq.0.2014.06.13.06.12.38
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Fri, 13 Jun 2014 06:12:38 -0700 (PDT)
Received-SPF: pass (google.com: domain of dribeas@gmail.com designates 2607:f8b0:400d:c01::235 as permitted sender) client-ip=2607:f8b0:400d:c01::235;
Original-Received: by mail-qc0-f181.google.com with SMTP id x13so4072150qcv.26
        for <std-proposals@isocpp.org>; Fri, 13 Jun 2014 06:12:37 -0700 (PDT)
X-Received: by 10.140.97.227 with SMTP id m90mr3322108qge.15.1402665157526;
 Fri, 13 Jun 2014 06:12:37 -0700 (PDT)
Original-Sender: dribeas@gmail.com
Original-Received: by 10.140.42.182 with HTTP; Fri, 13 Jun 2014 06:12:37 -0700 (PDT)
In-Reply-To: <fd784f28-1868-46d2-a211-8970b01388f9@isocpp.org>
X-Original-Sender: dibeas@ieee.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of dribeas@gmail.com designates 2607:f8b0:400d:c01::235 as permitted
 sender) smtp.mail=dribeas@gmail.com;       dkim=pass header.i=@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:11295
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11295>

--001a113a2a2e7408f304fbb76e4e
Content-Type: text/plain; charset=UTF-8

On Thu, Jun 12, 2014 at 3:14 PM, walter1234 <walter2bz@gmail.com> wrote:

> auto foo(...) {return...}   is certainly a great thing to have.
>
> the benefit of the type being in the signature however, is discoverability
> and documentation -
>

.... and being able to use the return type in an SFINAE context. [Personally
I believe that library code *should* always spell out the return type in
the signature, trailing return type is fine, return type being deduced not
so much].

This is a contrived example, but is concise enough to be sent over email:

std::string f(int);
void          f(double);

template <typename T>
auto g(T value) {
    return f(value);
}

template <typename T>
auto h(T value) -> decltype(g(value).size())
{
    return g(type).size();
}
template <typename T>
size_t h(T value, ...) {
    return size_t();
}

int main() {
    h(1.0);       // hard error!!
}

If the return type of 'g' had not been deduced the above would have
SFINAE-d out the first template and called the second overload of 'h'.

    David

-- 

--- 
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/.

--001a113a2a2e7408f304fbb76e4e
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">=
On Thu, Jun 12, 2014 at 3:14 PM, walter1234 <span dir=3D"ltr">&lt;<a href=
=3D"mailto:walter2bz@gmail.com" target=3D"_blank">walter2bz@gmail.com</a>&g=
t;</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 dir=3D"ltr">auto foo(...) {return...} =
=C2=A0 is certainly a great thing to have.<div><br><div>the benefit of the =
type being in the signature however, is discoverability and documentation -=
=C2=A0</div>
</div></div></blockquote><div><br>... and being able to use the return type=
 in an SFINAE context. [Personally I believe that library code *should* alw=
ays spell out the return type in the signature, trailing return type is fin=
e, return type being deduced not so much].<br>
<br>This is a contrived example, but is concise enough to be sent over emai=
l:<br><br>std::string f(int);<br>void =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0f(d=
ouble);</div><div><br>template &lt;typename T&gt;<br>auto g(T value) {<br>=
=C2=A0 =C2=A0 return f(value);<br>
}</div><div><br>template &lt;typename T&gt;<br>auto h(T value) -&gt; declty=
pe(g(value).size())<br>{<br>=C2=A0 =C2=A0 return g(type).size();<br>}<br>te=
mplate &lt;typename T&gt;<br>size_t h(T value, ...) {<br>=C2=A0 =C2=A0 retu=
rn size_t();<br>
}<br><br>int main() {<br>=C2=A0 =C2=A0 h(1.0); =C2=A0 =C2=A0 =C2=A0 // hard=
 error!!<br>}<br><br>If the return type of &#39;g&#39; had not been deduced=
 the above would have SFINAE-d out the first template and called the second=
 overload of &#39;h&#39;.<br>
<br>=C2=A0 =C2=A0 David<br><br></div></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 />

--001a113a2a2e7408f304fbb76e4e--

.
