220 4079 <CA+jCFLuz=RmEgfaDRDHEYAx1PYGR-qWTLJXQCgzyW7YHXHabzw@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Christopher Jefferson <chris@bubblescope.net>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Multiple return values
Date: Mon, 29 Apr 2013 16:33:22 +0100
Lines: 174
Approved: news@gmane.org
Message-ID: <CA+jCFLuz=RmEgfaDRDHEYAx1PYGR-qWTLJXQCgzyW7YHXHabzw@mail.gmail.com>
References: <269d4602-e158-4abc-a9a8-8c3cb453e013@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=047d7b6d89a2deee8b04db819a6e
X-Trace: ger.gmane.org 1367249604 30242 80.91.229.3 (29 Apr 2013 15:33:24 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 29 Apr 2013 15:33:24 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCF5NPH6QMFRBRNF7KFQKGQE3IAAEWY@isocpp.org Mon Apr 29 17:33:28 2013
Return-path: <std-proposals+bncBCF5NPH6QMFRBRNF7KFQKGQE3IAAEWY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vc0-f198.google.com ([209.85.220.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCF5NPH6QMFRBRNF7KFQKGQE3IAAEWY@isocpp.org>)
	id 1UWq51-0006fT-JG
	for gclcip-std-proposals@m.gmane.org; Mon, 29 Apr 2013 17:33:27 +0200
Original-Received: by mail-vc0-f198.google.com with SMTP id ha12sf6620426vcb.9
        for <gclcip-std-proposals@m.gmane.org>; Mon, 29 Apr 2013 08:33:26 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=google.com; s=20120113;
        h=x-received:x-beenthere:x-received:received-spf:mime-version
         :x-received:in-reply-to:references:date:message-id:subject:from:to
         :x-gm-message-state:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-google-group-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=MwvZnVisfV3bxCjan3zbs4aUmIP/75iT1qWM5WimYeM=;
        b=hdvYeqPb5cNDpGNroJcDi1fMF5D8xxcmQSSjkS8MVGB6i2/3KqEgGRFp5/LHOgDlkq
         z1R9YqziuUjVal+i0tEGqqh2svfqiFw5zQdjYnJKRjn21fo7V0Iw11jE00ote7VOjfa/
         omLDD2UzBzsgvzCKBPYKgy+64pQhIMIveWOpz7VLHQC/h9UScx+1ObLH/LE7lz7kNSYX
         MkFnj7xiTWariH1EYjYkH1L8sZv2GHdvTSKv4w9DZ4g8ooKeGm1tj4Ol17UndcpREd1q
         tdUNDxFW61FyAC9KAGxWkpIzaBJi/n3 
X-Received: by 10.236.161.234 with SMTP id w70mr29482987yhk.22.1367249606644;
        Mon, 29 Apr 2013 08:33:26 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.87.103 with SMTP id w7ls2653996qez.83.gmail; Mon, 29 Apr
 2013 08:33:22 -0700 (PDT)
X-Received: by 10.224.105.146 with SMTP id t18mr52442513qao.65.1367249602783;
        Mon, 29 Apr 2013 08:33:22 -0700 (PDT)
Original-Received: from mail-qe0-f41.google.com (mail-qe0-f41.google.com [209.85.128.41])
        by mx.google.com with ESMTPS id ht6si5587181qab.2.2013.04.29.08.33.22
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Mon, 29 Apr 2013 08:33:22 -0700 (PDT)
Received-SPF: neutral (google.com: 209.85.128.41 is neither permitted nor denied by best guess record for domain of chris@bubblescope.net) client-ip=209.85.128.41;
Original-Received: by mail-qe0-f41.google.com with SMTP id b10so218583qen.28
        for <std-proposals@isocpp.org>; Mon, 29 Apr 2013 08:33:22 -0700 (PDT)
X-Received: by 10.49.74.226 with SMTP id x2mr61559348qev.63.1367249602403;
 Mon, 29 Apr 2013 08:33:22 -0700 (PDT)
Original-Received: by 10.49.120.194 with HTTP; Mon, 29 Apr 2013 08:33:22 -0700 (PDT)
In-Reply-To: <269d4602-e158-4abc-a9a8-8c3cb453e013@isocpp.org>
X-Gm-Message-State: ALoCoQnyfPjTAsGIyuaE+Ij2HTgXyGWYmMeuzLpuGBttPVcTdpBm/uVy9t3k9j+kQ5LJofn7gwcr
X-Original-Sender: chris@bubblescope.net
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 209.85.128.41 is neither permitted nor denied by best guess
 record for domain of chris@bubblescope.net) smtp.mail=chris@bubblescope.net
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?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:4079
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/4079>

--047d7b6d89a2deee8b04db819a6e
Content-Type: text/plain; charset=ISO-8859-1

On 29 April 2013 15:03, Hariharan Subramanian <tohari@gmail.com> wrote:

> Problem:
> Having a single return value means we have to pass the other return values
> as parameters as a reference or a pointer. This makes the programs
> difficult to understand. Moreover we can solve most of the problems
> mentioned in
> http://www.openstd.org/JTC1/SC22/WG21/docs/papers/2013/n3538.html<http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2013/n3538.html>
> .
>

I decided to have a go at seeing how much of this could be done with
std::tuple.

>
> Solution:
> (int; float) foo (int);
>
std::tuple<int, float> foo(int);

> Probably a contextual keyword returns can be added to specify that the
> first pair of parentheses represents return values. So we will be passing
> only in parameters and in out parameters to the function. All the out
> parameters are only returned.
>
> With this we can write the code
>
> int a;
> float b;
> (a; b) = foo(a, b);
>
std::tie(a,b) = foo(a,b);

> (int c; float d) = foo(a, b);
>
This one we have to write:
int c; float d;
std::tie(c, d) = foo(a,b);

>
> We can pass the return values to functions. We can write foo( foo(a, b) );
>
Now you are automatically unpacking tuples. What happens if foo takes a
tuple? This case doesn't work, but you have to be careful.

>
> We can compare the return values. The semantics can be defined as the
> operation should be true for all the return values.
> foo(a,  b) == foo(c, d), foo(a, b) >= foo(c, d) etc.,
>
Works with std::tuple already

>
> We cab do the following also
> (c, d) == foo(a, b), (c, d) > foo(a, b) etc.,
>
std::tie(c,d) == foo(a,b), std::tie(c,d) > foo(a,b);

>
> (a, b) = (b, a) swaps the values. It should generate the code equivalent to
>
This one, I wouldn't be confident doing with tie (but it might work).
However, we have swap :)



> There are some problem areas like type casting. Probably they can be
> prohibited. Other issues may remain and need to be discussed.
>

The main problem (as I outline in my mail) is that many of these things can
be done with std::tuple and std::tie. If this is just syntatic sugar over
std::tuple and std::tie, then is it worth it, and if it is a seperate kind
of tuple, we have to worry about the two interacting.

-- 

--- 
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/?hl=en.



--047d7b6d89a2deee8b04db819a6e
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><br><br><div class=3D"gmail=
_quote">On 29 April 2013 15:03, Hariharan Subramanian <span dir=3D"ltr">&lt=
;<a href=3D"mailto:tohari@gmail.com" target=3D"_blank">tohari@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">Problem:<div>Having a single return value me=
ans we have to pass the other return values as parameters as a reference or=
 a pointer. This makes the programs difficult to understand. Moreover we ca=
n solve most of the problems mentioned in=A0<a href=3D"http://www.open-std.=
org/JTC1/SC22/WG21/docs/papers/2013/n3538.html" target=3D"_blank">http://ww=
w.openstd.org/JTC1/SC22/WG21/docs/papers/2013/n3538.html</a>.=A0</div>
</blockquote><div><br></div><div style>I decided to have a go at seeing how=
 much of this could be done with std::tuple.=A0</div><blockquote class=3D"g=
mail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-l=
eft:1ex">
<div><br></div><div>Solution:</div><div>(int; float) foo (int);</div></bloc=
kquote><div style>std::tuple&lt;int, float&gt; foo(int);=A0</div><blockquot=
e class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc sol=
id;padding-left:1ex">
<div>Probably a contextual keyword returns can be added to specify that the=
 first pair of parentheses represents return values. So we will be passing =
only in parameters and in out parameters to the function. All the out param=
eters are only returned.</div>
<div><br></div><div>With this we can write the code</div><div><br></div><di=
v>int a;</div><div>float b;</div><div>(a; b) =3D foo(a, b);</div></blockquo=
te><div style>std::tie(a,b) =3D foo(a,b);=A0</div><blockquote class=3D"gmai=
l_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left=
:1ex">
<div>(int c; float d) =3D foo(a, b);</div></blockquote><div style>This one =
we have to write:</div><div style>int c; float d;</div><div style>std::tie(=
c, d) =3D foo(a,b);=A0</div><blockquote class=3D"gmail_quote" style=3D"marg=
in:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><br></div><div>We can pass the return values to functions. We can writ=
e foo( foo(a, b) );<br></div></blockquote><div style>Now you are automatica=
lly unpacking tuples. What happens if foo takes a tuple? This case doesn&#3=
9;t work, but you have to be careful.=A0</div>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex"><div><br></div><div>We can compare the retur=
n values. The semantics can be defined as the operation should be true for =
all the return values.</div>
<div>foo(a, =A0b) =3D=3D foo(c, d), foo(a, b) &gt;=3D foo(c, d) etc.,<br></=
div></blockquote><div style>Works with std::tuple already</div><blockquote =
class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid=
;padding-left:1ex">
<div></div><div><br></div><div>We cab do the following also</div><div>(c, d=
) =3D=3D foo(a, b), (c, d) &gt; foo(a, b) etc.,</div></blockquote><div styl=
e>std::tie(c,d) =3D=3D foo(a,b), std::tie(c,d) &gt; foo(a,b);=A0</div><bloc=
kquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #cc=
c solid;padding-left:1ex">
<div><br></div><div>(a, b) =3D (b, a) swaps the values. It should generate =
the code equivalent to</div></blockquote><div style>This one, I wouldn&#39;=
t be confident doing with tie (but it might work). However, we have swap :)=
=A0</div>
<div><br></div><div>=A0<br></div><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>There =
are some problem areas like type casting. Probably they can be prohibited. =
Other issues may remain and need to be discussed.<br>
</div></blockquote><div><br></div><div style>The main problem (as I outline=
 in my mail) is that many of these things can be done with std::tuple and s=
td::tie. If this is just syntatic sugar over std::tuple and std::tie, then =
is it worth it, and if it is a seperate kind of tuple, we have to worry abo=
ut the two interacting.</div>
</div></div></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

--047d7b6d89a2deee8b04db819a6e--

.
