220 20962 <CAB+4KHLBYKxVQsSd_Q-LybNLdx5W9vLJ1HKY6Um8Lwe7vVKE1w@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Andrew Tomazos <andrewtomazos@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: auto return
Date: Tue, 29 Sep 2015 06:10:15 +0200
Lines: 100
Approved: news@gmane.org
Message-ID: <CAB+4KHLBYKxVQsSd_Q-LybNLdx5W9vLJ1HKY6Um8Lwe7vVKE1w@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a11c2b90cb970f00520dafd2a
X-Trace: ger.gmane.org 1443499818 23110 80.91.229.3 (29 Sep 2015 04:10:18 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 29 Sep 2015 04:10:18 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBD5KHQXXWYPRBKE6VCYAKGQEELD7UQY@isocpp.org Tue Sep 29 06:10:18 2015
Return-path: <std-proposals+bncBD5KHQXXWYPRBKE6VCYAKGQEELD7UQY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-la0-f69.google.com ([209.85.215.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBD5KHQXXWYPRBKE6VCYAKGQEELD7UQY@isocpp.org>)
	id 1ZgmF7-0003Pj-PH
	for gclcip-std-proposals@m.gmane.org; Tue, 29 Sep 2015 06:10:17 +0200
Original-Received: by labnm6 with SMTP id nm6sf8415678lab.1
        for <gclcip-std-proposals@m.gmane.org>; Mon, 28 Sep 2015 21:10:17 -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:date:message-id:subject:from: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=SU59jDJ8RTlaXXKkVWLA/Oc2H/qn3KmTy1LN3wDjQU0=;
        b=JqpQMalBn2feSJ7nlX21Lk2yuI5+2gTsHZ0XhaqNQiOgT6ga97DQgZdiRpA6BLXOn6
         cE91IzZtD5+A1gh5llWnfpZ4n16xHPvNw6asKxfNlJGRzw7r+R46Y5P40e78RC1AX4f0
         L1m0od4LF5cYYH/0BJIK4bqCS94frfzr55S/60mZzZwdeb2lwS8Hwqe166PORPNbwEmD
         2KU2JGhIUgv4U8cf7GolVDoco0sHwdDooqMwUi2LzoNZ7cSwD43euhgJrqaLB6zPLa12
         AZEW+gm/6QSTXBntuznqwnJFfZfFPaGIr5z6Uxu7MMKiE+eY/7Qu3K5Xzsf1HCjH8Ovd
         3Snw==
X-Gm-Message-State: ALoCoQmpGSgC5PGBF+YUvRNxho08edBjg2cGvvv92p7PB/7fCWFIzo7Xw/tmXbnpaWCfQSDF7LdN
X-Received: by 10.180.160.146 with SMTP id xk18mr3434469wib.3.1443499816999;
        Mon, 28 Sep 2015 21:10:16 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.253.231 with SMTP id ad7ls666971wid.11.gmail; Mon, 28 Sep
 2015 21:10:15 -0700 (PDT)
X-Received: by 10.194.114.199 with SMTP id ji7mr24009218wjb.19.1443499815631;
        Mon, 28 Sep 2015 21:10:15 -0700 (PDT)
Original-Received: from mail-wi0-x22d.google.com (mail-wi0-x22d.google.com. [2a00:1450:400c:c05::22d])
        by mx.google.com with ESMTPS id qt4si26735396wic.79.2015.09.28.21.10.15
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 28 Sep 2015 21:10:15 -0700 (PDT)
Received-SPF: pass (google.com: domain of andrewtomazos@gmail.com designates 2a00:1450:400c:c05::22d as permitted sender) client-ip=2a00:1450:400c:c05::22d;
Original-Received: by wicfx3 with SMTP id fx3so131462245wic.1
        for <std-proposals@isocpp.org>; Mon, 28 Sep 2015 21:10:15 -0700 (PDT)
X-Received: by 10.180.10.197 with SMTP id k5mr20976331wib.22.1443499815299;
 Mon, 28 Sep 2015 21:10:15 -0700 (PDT)
Original-Received: by 10.28.73.137 with HTTP; Mon, 28 Sep 2015 21:10:15 -0700 (PDT)
X-Original-Sender: andrewtomazos@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of andrewtomazos@gmail.com designates 2a00:1450:400c:c05::22d as
 permitted sender) smtp.mailfrom=andrewtomazos@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:20962
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20962>

--001a11c2b90cb970f00520dafd2a
Content-Type: text/plain; charset=UTF-8

It is a common pattern to declare a local variable of the return type of
the enclosing function, mutate it into the required result, and then return
it...

  std::vector<std::pair<int,int>> build_points() {
    std::vector<std::pair<int,int>> result;
    while (c) result.emplace_back(g(c),h(c));
    return result;
  }

First, imagine we defined `auto return` as a kind of decl-specifier that
implied these two things:

  1. The declared variable has the return type of the enclosing function.
  2. The variable is automatically returned when the function falls off the
end:

  std::vector<std::pair<int,int>> build_points() {
    auto return result;
    while (c) result.emplace_back(g(c),h(c));
  }

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));
  }

Now suppose we said that if the expression return appears in a function,
the auto return declaration is created implicitly:

  std::vector<std::pair<int,int>> build_points() {
    while (c) return.emplace_back(g(c),h(c));
  }

Let me know if there is interest.

-- 

--- 
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/.

--001a11c2b90cb970f00520dafd2a
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">It is a common pattern to declare a local variable of the =
return type of the enclosing function, mutate it into the required result, =
and then return it...<div><div><br class=3D"">=C2=A0 std::vector&lt;std::pa=
ir&lt;int,int&gt;&gt; build_points() {</div><div>=C2=A0 =C2=A0=C2=A0std::ve=
ctor&lt;std::pair&lt;int,int&gt;&gt;=C2=A0result;</div><div>=C2=A0 =C2=A0 w=
hile (c)=C2=A0result.emplace_back(g(c),h(c));</div><div>=C2=A0 =C2=A0 retur=
n=C2=A0result;<br></div><div>=C2=A0 }</div></div><div><br></div><div>First,=
 imagine we defined `auto return` as a kind of decl-specifier that implied =
these two things:</div><div><br></div><div>=C2=A0 1. The declared variable =
has the return type of the enclosing function.</div><div>=C2=A0 2. The vari=
able is automatically returned when the function falls off the end:</div><d=
iv><br></div><div>=C2=A0=C2=A0std::vector&lt;std::pair&lt;int,int&gt;&gt; b=
uild_points()=C2=A0{</div><div>=C2=A0 =C2=A0 auto return=C2=A0result;</div>=
<div>=C2=A0 =C2=A0 while (c)=C2=A0result.emplace_back(g(c),h(c));</div><div=
>=C2=A0 }<br></div><div><br></div><div>Now suppose we said that this variab=
le could be unnamed, and in such cases the keyword return could be used as =
an id-expression to refer to this return value:</div><div><br></div><div><d=
iv>=C2=A0 std::vector&lt;std::pair&lt;int,int&gt;&gt; build_points()=C2=A0{=
</div><div>=C2=A0 =C2=A0 auto return;</div><div>=C2=A0 =C2=A0 while (c) ret=
urn.emplace_back(g(c),h(c));</div><div>=C2=A0 }<br></div></div><div><br></d=
iv><div>Now suppose we said that if the expression return appears in a func=
tion, the auto return declaration is created implicitly:</div><div><br></di=
v><div><div>=C2=A0 std::vector&lt;std::pair&lt;int,int&gt;&gt; build_points=
()=C2=A0{</div><div>=C2=A0 =C2=A0 while (c) return.emplace_back(g(c),h(c));=
<br></div><div>=C2=A0 }<br></div></div><div><br></div><div>Let me know if t=
here is interest.</div><div><br></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 />

--001a11c2b90cb970f00520dafd2a--

.
