220 20990 <CANCWpS_DU5nDQ=6qM7NsdoS3Rq+qfh2vpFTsKWQxR1BSXWpt_w@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: little3lue <little3lue@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: auto return
Date: Tue, 29 Sep 2015 20:08:40 +0000
Lines: 418
Approved: news@gmane.org
Message-ID: <CANCWpS_DU5nDQ=6qM7NsdoS3Rq+qfh2vpFTsKWQxR1BSXWpt_w@mail.gmail.com>
References: <CAB+4KHLBYKxVQsSd_Q-LybNLdx5W9vLJ1HKY6Um8Lwe7vVKE1w@mail.gmail.com>
 <7deedcff-6776-4b3b-a3d1-3132f8ec1ae3@isocpp.org> <CAB+4KHJ-8aY9AF6fOzi6ZUv1=Mfqe-9BVKe6Ou+X_KXQk_zM3g@mail.gmail.com>
 <489434f4-b703-4b0a-ad28-833899af1e14@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=94eb2c032818e9255d0520e8613a
X-Trace: ger.gmane.org 1443557339 22366 80.91.229.3 (29 Sep 2015 20:08:59 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 29 Sep 2015 20:08:59 +0000 (UTC)
To: "ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBC46VCEIWUFBBU67VOYAKGQEYKXNISI@isocpp.org Tue Sep 29 22:08:55 2015
Return-path: <std-proposals+bncBC46VCEIWUFBBU67VOYAKGQEYKXNISI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vk0-f71.google.com ([209.85.213.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBC46VCEIWUFBBU67VOYAKGQEYKXNISI@isocpp.org>)
	id 1Zh1Co-0000hy-OU
	for gclcip-std-proposals@m.gmane.org; Tue, 29 Sep 2015 22:08:55 +0200
Original-Received: by vkgd64 with SMTP id d64sf22818471vkg.2
        for <gclcip-std-proposals@m.gmane.org>; Tue, 29 Sep 2015 13:08:53 -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:references:in-reply-to:from:date
         :message-id:subject:to:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=YfE6i+f/updo6D4LuAko/P4lu7Sf4A3RFAPH4CPRCBc=;
        b=Mk7BSrdxNbsn1l2WWM8rvhtizAZtA3ze2du8HbwPGQOwToSsL/JNooGCkFVH9AlY4j
         ogmSboj8THLV1ThNx3sWMhtyp6KzOCj8dLfTwMgSci3WN7LosazS7pZyAPzkJW6gtnhP
         NX+eKarGcM3jp5blDde0nVcYHjPxcMMhNA/2fFzQcBDxXQU/KAZ404MI0EwX2xPb4P9i
         d4dFhN8VN7z/AfHONgWP3h1Uk381Y6TgJj0o5rvfZKNlf78vSD1EC2PONs+cLHWzDKFg
         yTf3gjnazAojb/Pi/dQkGz2ebHru5UxUqRqVS85QRvrRe3CZqW1OJsjLuG/PqzADVpFl
         ETsA==
X-Gm-Message-State: ALoCoQnW0cVV+IjPkOxUpCmBkPKzc03OIn8YSzwQEnIRmqEIIa2Y6VXUZK6I7Z9Ho75TP+Z+b9Mk
X-Received: by 10.31.3.93 with SMTP id 90mr24946233vkd.0.1443557333660;
        Tue, 29 Sep 2015 13:08:53 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.22.135 with SMTP id 7ls7134qgn.58.gmail; Tue, 29 Sep 2015
 13:08:51 -0700 (PDT)
X-Received: by 10.170.215.195 with SMTP id h186mr23309342ykf.126.1443557331144;
        Tue, 29 Sep 2015 13:08:51 -0700 (PDT)
Original-Received: from mail-yk0-x233.google.com (mail-yk0-x233.google.com. [2607:f8b0:4002:c07::233])
        by mx.google.com with ESMTPS id x81si12491547ywc.185.2015.09.29.13.08.51
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 29 Sep 2015 13:08:51 -0700 (PDT)
Received-SPF: pass (google.com: domain of little3lue@gmail.com designates 2607:f8b0:4002:c07::233 as permitted sender) client-ip=2607:f8b0:4002:c07::233;
Original-Received: by ykdt18 with SMTP id t18so18656190ykd.3
        for <std-proposals@isocpp.org>; Tue, 29 Sep 2015 13:08:50 -0700 (PDT)
X-Received: by 10.13.240.71 with SMTP id z68mr23970066ywe.65.1443557330722;
 Tue, 29 Sep 2015 13:08:50 -0700 (PDT)
In-Reply-To: <489434f4-b703-4b0a-ad28-833899af1e14@isocpp.org>
X-Original-Sender: LittLe3Lue@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of little3lue@gmail.com designates 2607:f8b0:4002:c07::233 as
 permitted sender) smtp.mailfrom=little3lue@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-Spam-Checked-In-Group: 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:20990
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20990>

--94eb2c032818e9255d0520e8613a
Content-Type: text/plain; charset=UTF-8

Some languages allow creating a named variable for the return type, as part
of the function definition.

E.g. strawman:

// foo.h
Foo getFoo();

// foo.cpp
(Foo foo) getFoo() {
  // foo is initialized and "automatically returned" unless another value
is explicitly returned
  foo.fizzle();
}

// Or maybe:
auto getFoo -> Foo foo {
}

-Michal

On Tue, Sep 29, 2015 at 10:09 AM Nicol Bolas <jmckesson@gmail.com> wrote:

> On Tuesday, September 29, 2015 at 2:28:58 AM UTC-4, Andrew Tomazos wrote:
>>
>> Thanks for your feedback.  Questions answered below..
>>
>
>> On Tuesday, September 29, 2015 at 12:10:18 AM UTC-4, Andrew Tomazos wrote:On
>>> Tue, Sep 29, 2015 at 7:27 AM, Nicol Bolas <jmck...@gmail.com> wrote:
>>>
>> Now suppose we said that this variable could be unnamed, and in such
>>>> cases the keyword return could be used as an id-expression to refer to this
>>>> return value:
>>>>
>>>>   std::vector<std::pair<int,int>> build_points() {
>>>>     auto return;
>>>>     while (c) return.emplace_back(g(c),h(c));
>>>>   }
>>>>
>>>
>>> Why would you *want* an unnamed variable? Is typing a variable name
>>> somehow complicated? Is it an onerous burden for the user? Even in the
>>> context of implicit return, using the variable name rather than `return`
>>> makes far more sense.
>>>
>>
>> There are a number of places in the language where an unnamed entity is
>> defined, used or deduced.  I guess the motivation is the same as for those.
>>
>
> For values, yes this is true. However, those values are always (as far as
> I recall) *temporaries* that do not outlive the line in which they are
> generated. You're talking about deliberately declaring an unnamed
> *variable*.
>
> That's very new for C++.
>
> Equally importantly, it's really confusing the issue. Are you saying that
>>> `return.blah` is an expression or is it a return statement that evaluates
>>> and returns an expression? Because the use of the word `return` strongly
>>> suggests the latter, not the former.
>>>
>>
>> If you're saying that there is some visual ambiguity, then that may be so.
>>
>
> Yes, I was talking about user confusion. But parsing ambiguities don't
> help your case.
>
> As for parsing ambiguity, return.blah is not one. return.blah is
>> unambiguously an expression.  The LHS is the id-expression refering to the
>> auto return object.
>>
>
> Let's say we use your suggested parsing rule of "if it can be a return
> statement, it is a return statement".
>
> So let's consider `return 5;`. That's a return statement. But did you
> *mean* for it to be a return statement? Or did you mean `return = 5` and
> you accidentally typed the wrong thing? If your return type is implicitly
> convertible from an integer, the compiler will accept either one. And the
> two mean very different things, with `return 5` immediately halting
> execution.
>
> That is a very nasty, completely *silent* breakage. That's bad.
>
> FYI: rules like the one you suggest gave us the Most Vexing Parse
> <https://en.wikipedia.org/wiki/Most_vexing_parse>. We should not
> deliberately add features like that again.
>
> If you had just introduced an actual name, that wouldn't be necessary.
>
> There are some parsing ambiguities like:
>>
>>    return(x);
>>
>> Is this an expression statement calling operator() of the return object,
>> or a return statement returning x.  These ambiguities would have to be
>> resolved as part of the proposal (most likely "if it can be a return
>> statement, it is a return statement").
>>
>
> Which would limit the ways in which you can use this implicit variable.
> You can't even call operator() on it without shenanigans (like `(return)()`
> or whatever). Though at least that may well be a noisy breakage.
>
>
>> Is it default initialized or value initialized.
>>>
>>
>> It is as-if it was declared without an initializer:
>>
>>   T f() {
>>     T x;  // <-- like this
>>
>> I can't remember which this implies off the top of my head.
>>
>
> That's default initialization
> <http://en.cppreference.com/w/cpp/language/default_initialization>, so
> for many types, they go uninitialized. That's generally considered bad
> these days. Or at least, it's not good for it to be the default case.
>
> What if the type doesn't have a default constructor,
>>>
>>
>> Ill-formed.
>>
>
>>
> or if I want to call a different constructor?
>>>
>>
>> With the third implicit form, you can't.
>>
>
> Doesn't this restriction significantly limit how much users can use this
> "common pattern"? Even if only 30% of uses of this pattern used a
> non-default constructor, that's still almost 1/3rd of potential users who
> can't use this feature.
>
> So ultimately, all they save is a return at the bottom of the function.
> Again, is that *one line* worth the syntactic burden?
>
>
>> What if the default constructor throws; how would you catch the exception?
>>>
>>
>> I can't remember if this works:
>>
>>     void f() {
>>       return++;
>>     } catch (...) {
>>     }
>>
>> But if it does, it would catch an exception thrown from the return
>> constructor.
>>
>
> Well, that particular syntax doesn't work. But it is possible to create function-level
> try/catch blocks
> <http://en.cppreference.com/w/cpp/language/function-try-block>.
>
> But really, you shouldn't encourage that.
>
>
>> And most importantly, why is this at all worthwhile? Seriously, is
>>> declaring a variable and returning it really that hard?
>>>
>>
>> The motivation is mainly providing a terser syntax for an, in my opinion,
>> common pattern (as an example, a similar motivation to, although much
>> smaller than, lambdas).
>>
>
> You're saving 2 lines of code. In a function that's just 10 lines long
> (including declaration and {}s), that's only a 20% reduction in code size.
> And the shorter said code is, the *less* likely it is that you will need
> to use this pattern.
>
> And you can only save two lines of code if you use the
> default-construct-followed-by-initialization pattern. If you need to use an
> actual constructor, you save... one line of code. Only 10% in a 10 line
> function.
>
> If a full quarter of your functions use the first pattern (and I rather
> doubt it's even that common), you will save maybe 5% of actual lines of
> text.
>
> So even if this pattern were common, you ultimately don't save much. And
> the downsides of the feature make  it harder to reason about code (thanks
> to `return` ambiguities), introduce unnamed variables, and make functions
> behave in a way that is very new (automatically returning values).
>
> Lambdas save you tons of very difficult-to-write code, especially if they
> capture values. Thus far, your feature saves you 2 lines of
> trivial-to-write code.
>
> So I'm failing to see the cost/benefit here.
>
> --
>
> ---
> 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/.

--94eb2c032818e9255d0520e8613a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Some languages allow creating a named variable for the ret=
urn type, as part of the function definition.<div><br></div><div>E.g. straw=
man:</div><div><br></div><div>// foo.h</div><div>Foo getFoo();</div><div><b=
r></div><div>// foo.cpp</div><div>(Foo foo) getFoo() {</div><div>=C2=A0 // =
foo is initialized and &quot;automatically returned&quot; unless another va=
lue is explicitly returned</div><div>=C2=A0 foo.fizzle();</div><div>}</div>=
<div><br></div><div>// Or maybe:</div><div>auto getFoo -&gt; Foo foo {</div=
><div>}</div><div><br></div><div>-Michal</div></div><br><div class=3D"gmail=
_quote"><div dir=3D"ltr">On Tue, Sep 29, 2015 at 10:09 AM Nicol Bolas &lt;<=
a href=3D"mailto:jmckesson@gmail.com">jmckesson@gmail.com</a>&gt; wrote:<br=
></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-=
left:1px #ccc solid;padding-left:1ex">On Tuesday, September 29, 2015 at 2:2=
8:58 AM UTC-4, Andrew Tomazos wrote:<blockquote class=3D"gmail_quote" style=
=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"=
><div dir=3D"ltr">Thanks for your feedback.=C2=A0 Questions answered below.=
..<br></div></blockquote><blockquote class=3D"gmail_quote" style=3D"margin:0=
;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D=
"ltr"><div><br><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote"=
 style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><s=
pan>On Tuesday, September 29, 2015 at 12:10:18 AM UTC-4, Andrew Tomazos wro=
te:</span>On Tue, Sep 29, 2015 at 7:27 AM, Nicol Bolas <span dir=3D"ltr">&l=
t;<a rel=3D"nofollow">jmck...@gmail.com</a>&gt;</span> wrote:<br></blockquo=
te><div></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;=
border-left:1px #ccc solid;padding-left:1ex"><div></div><span><blockquote c=
lass=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #c=
cc solid;padding-left:1ex"><div dir=3D"ltr"><div></div><div></div><div>Now =
suppose we said that this variable could be unnamed, and in such cases the =
keyword return could be used as an id-expression to refer to this return va=
lue:</div><div><br></div><div><div>=C2=A0 std::vector&lt;std::pair&lt;int,i=
nt&gt;&gt; build_points()=C2=A0{</div><div>=C2=A0 =C2=A0 auto return;</div>=
<div>=C2=A0 =C2=A0 while (c) return.emplace_back(g(c),h(c));</div><div>=C2=
=A0 }<br></div></div></div></blockquote></span><div><br>Why would you <i>wa=
nt</i> an unnamed variable? Is typing a variable name somehow complicated? =
Is it an onerous burden for the user? Even in the context of implicit retur=
n, using the variable name rather than `return` makes far more sense.<br></=
div></blockquote><div>=C2=A0</div><div>There are a number of places in the =
language where an unnamed entity is defined, used or deduced.=C2=A0 I guess=
 the motivation is the same as for those.</div></div></div></div></blockquo=
te><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;bo=
rder-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"></div></blockqu=
ote><div><br>For values, yes this is true. However, those values are always=
 (as far as I recall) <i>temporaries</i> that do not outlive the line in wh=
ich they are generated. You&#39;re talking about deliberately declaring an =
unnamed <i>variable</i>.<br><br>That&#39;s very new for C++.<br><br></div><=
blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border=
-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"=
gmail_quote"><div></div><blockquote class=3D"gmail_quote" style=3D"margin:0=
 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Equally importa=
ntly, it&#39;s really confusing the issue. Are you saying that `return.blah=
` is an expression or is it a return statement that evaluates and returns a=
n expression? Because the use of the word `return` strongly suggests the la=
tter, not the former.<br></div></blockquote><div>=C2=A0</div><div>If you&#3=
9;re saying that there is some visual ambiguity, then that may be so.</div>=
</div></div></div></blockquote><div><br>Yes, I was talking about user confu=
sion. But parsing ambiguities don&#39;t help your case.<br><br></div><block=
quote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail=
_quote"><div></div><div>As for parsing ambiguity, return.blah is not one. r=
eturn.blah is unambiguously an expression.=C2=A0 The LHS is the id-expressi=
on refering to the auto return object.</div></div></div></div></blockquote>=
<div><br>Let&#39;s say we use your suggested parsing rule of &quot;if it ca=
n be a return statement, it is a return statement&quot;.<br><br>So let&#39;=
s consider `return 5;`. That&#39;s a return statement. But did you <i>mean<=
/i> for it to be a return statement? Or did you mean `return =3D 5` and you=
 accidentally typed the wrong thing? If your return type is implicitly conv=
ertible from an integer, the compiler will accept either one. And the two m=
ean very different things, with `return 5` immediately halting execution.<b=
r><br>That is a very nasty, completely <i>silent</i> breakage. That&#39;s b=
ad.<br><br>FYI: rules like the one you suggest gave us the <a href=3D"https=
://en.wikipedia.org/wiki/Most_vexing_parse" target=3D"_blank">Most Vexing P=
arse</a>. We should not deliberately add features like that again.<br><br>I=
f you had just introduced an actual name, that wouldn&#39;t be necessary.<b=
r><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left=
:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><=
div class=3D"gmail_quote"><div></div><div>There are some parsing ambiguitie=
s like:</div><div><br></div><div>=C2=A0 =C2=A0return(x);</div><div><br></di=
v><div>Is this an expression statement calling operator() of the return obj=
ect, or a return statement returning x.=C2=A0 These ambiguities would have =
to be resolved as part of the proposal (most likely &quot;if it can be a re=
turn statement, it is a return statement&quot;).</div></div></div></div></b=
lockquote><div><br>Which would limit the ways in which you can use this imp=
licit variable. You can&#39;t even call operator() on it without shenanigan=
s (like `(return)()` or whatever). Though at least that may well be a noisy=
 breakage.<br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin=
:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=
=3D"ltr"><div><div class=3D"gmail_quote"><div></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-le=
ft:1ex"><div>Is it default initialized or value initialized.</div></blockqu=
ote><div><br></div><div>It is as-if it was declared without an initializer:=
</div><div><br></div><div>=C2=A0 T f() {</div><div>=C2=A0 =C2=A0 T x; =C2=
=A0// &lt;-- like this</div><div>=C2=A0</div><div>I can&#39;t remember whic=
h this implies off the top of my head.</div></div></div></div></blockquote>=
<div><br>That&#39;s <a href=3D"http://en.cppreference.com/w/cpp/language/de=
fault_initialization" target=3D"_blank">default initialization</a>, so for =
many types, they go uninitialized. That&#39;s generally considered bad thes=
e days. Or at least, it&#39;s not good for it to be the default case.<br><b=
r></div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8=
ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div =
class=3D"gmail_quote"><div></div><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div> What =
if the type doesn&#39;t have a default constructor,</div></blockquote><div>=
<br></div><div>Ill-formed.</div></div></div></div></blockquote><blockquote =
style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);pa=
dding-left:1ex" class=3D"gmail_quote"><div>=C2=A0</div></blockquote><div></=
div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;b=
order-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div><div clas=
s=3D"gmail_quote"><div></div><blockquote class=3D"gmail_quote" style=3D"mar=
gin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div> or if I w=
ant to call a different constructor? </div></blockquote><div><br></div><div=
>With the third implicit form, you can&#39;t.</div></div></div></div></bloc=
kquote><div><br>Doesn&#39;t this restriction significantly limit how much u=
sers can use this &quot;common pattern&quot;? Even if only 30% of uses of t=
his pattern used a non-default constructor, that&#39;s still almost 1/3rd o=
f potential users who can&#39;t use this feature.<br><br>So ultimately, all=
 they save is a return at the bottom of the function. Again, is that <i>one=
 line</i> worth the syntactic burden?<br>=C2=A0</div><blockquote class=3D"g=
mail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;=
padding-left:1ex"><div dir=3D"ltr"><div><div class=3D"gmail_quote"><div></d=
iv><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div>What if the default constructor thro=
ws; how would you catch the exception?<br></div></blockquote><div><br></div=
><div>I can&#39;t remember if this works:</div><div><br></div><div>=C2=A0 =
=C2=A0 void f() {</div><div>=C2=A0 =C2=A0 =C2=A0 return++;</div><div>=C2=A0=
 =C2=A0 } catch (...) {</div><div>=C2=A0 =C2=A0 }</div><div><br></div><div>=
But if it does, it would catch an exception thrown from the return construc=
tor.</div></div></div></div></blockquote><div><br>Well, that particular syn=
tax doesn&#39;t work. But it is possible to create <a href=3D"http://en.cpp=
reference.com/w/cpp/language/function-try-block" target=3D"_blank">function=
-level try/catch blocks</a>.<br><br>But really, you shouldn&#39;t encourage=
 that.<br>=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0;m=
argin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"l=
tr"><div><div class=3D"gmail_quote"><div></div><div></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div>And most importantly, why is this at all worthwhile? Ser=
iously, is declaring a variable and returning it really that hard?<br></div=
></blockquote><div>=C2=A0</div><div>The motivation is mainly providing a te=
rser syntax for an, in my opinion, common pattern (as an example, a similar=
 motivation to, although much smaller than, lambdas).</div></div></div></di=
v></blockquote><div><br>You&#39;re saving 2 lines of code. In a function th=
at&#39;s just 10 lines long (including declaration and {}s), that&#39;s onl=
y a 20% reduction in code size. And the shorter said code is, the <i>less</=
i> likely it is that you will need to use this pattern.<br><br>And you can =
only save two lines of code if you use the default-construct-followed-by-in=
itialization pattern. If you need to use an actual constructor, you save...=
 one line of code. Only 10% in a 10 line function.<br><br>If a full quarter=
 of your functions use the first pattern (and I rather doubt it&#39;s even =
that common), you will save maybe 5% of actual lines of text.<br><br>So eve=
n if this pattern were common, you ultimately don&#39;t save much. And the =
downsides of the feature make=C2=A0 it harder to reason about code (thanks =
to `return` ambiguities), introduce unnamed variables, and make functions b=
ehave in a way that is very new (automatically returning values).<br><br>La=
mbdas save you tons of very difficult-to-write code, especially if they cap=
ture values. Thus far, your feature saves you 2 lines of trivial-to-write c=
ode.<br><br>So I&#39;m failing to see the cost/benefit here.<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" target=3D"_=
blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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>
</blockquote></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 />

--94eb2c032818e9255d0520e8613a--

.
