220 4067 <269d4602-e158-4abc-a9a8-8c3cb453e013@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Hariharan Subramanian <tohari@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Multiple return values
Date: Mon, 29 Apr 2013 07:03:16 -0700 (PDT)
Lines: 122
Approved: news@gmane.org
Message-ID: <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="----=_Part_3796_26940885.1367244196978"
X-Trace: ger.gmane.org 1367244199 30598 80.91.229.3 (29 Apr 2013 14:03:19 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 29 Apr 2013 14:03:19 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCJZFFHTQQIBBJX37GFQKGQEMXAE2OQ@isocpp.org Mon Apr 29 16:03:21 2013
Return-path: <std-proposals+bncBCJZFFHTQQIBBJX37GFQKGQEMXAE2OQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ia0-f197.google.com ([209.85.210.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCJZFFHTQQIBBJX37GFQKGQEMXAE2OQ@isocpp.org>)
	id 1UWofo-00032U-9B
	for gclcip-std-proposals@m.gmane.org; Mon, 29 Apr 2013 16:03:20 +0200
Original-Received: by mail-ia0-f197.google.com with SMTP id u20sf22921632iag.8
        for <gclcip-std-proposals@m.gmane.org>; Mon, 29 Apr 2013 07:03:19 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-received:x-beenthere:x-received:date:from:to:message-id:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-google-group-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=bVg5uOmgj7GSfXoARL7xBfvWrkziB9dCfypRHmQpkGA=;
        b=onNEksBSwU9ibhuWIWl5Y1bfTGjziS0HaqNeapke+b7OXole9Q0tEW+DN9Swg9e4L6
         Wz68yG2oPjOTvWAjGata9n2pp6OKzHrFr24n60d8zWjxxEU15axFWRTR7t73WwEL66KP
         f0PCG1XTmKDIn+OOY1hD1IiZjIAgsnblUqQk48XYn+CVXvaRV8KGoUTTPEZYSmXEChwn
         h8PcOXpqfba2sYhRA0P0WjXMSvElswAqKgyFE/dxMz92asYTMsWyvqHGjsAM4ZAHnm3C
         /3cBwrOgBkEd9b50y2aWlVkCM+cq1JelKCswvXhROPOZX5EtaO1gmBLiq/BZVYWez/CL
         NiHg==
X-Received: by 10.182.56.231 with SMTP id d7mr10870972obq.8.1367244199092;
        Mon, 29 Apr 2013 07:03:19 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.182.98.161 with SMTP id ej1ls477394obb.31.gmail; Mon, 29 Apr
 2013 07:03:18 -0700 (PDT)
X-Received: by 10.182.237.108 with SMTP id vb12mr92500obc.18.1367244198259;
        Mon, 29 Apr 2013 07:03:18 -0700 (PDT)
X-Original-Sender: tohari@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?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:4067
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/4067>

------=_Part_3796_26940885.1367244196978
Content-Type: text/plain; charset=ISO-8859-1

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>
.. 

Solution:
(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);
(int c; float d) = foo(a, b);

If foo returns int & instead of int then we need to write

(int &c; float d) = foo(a, b);

If we decide to ignore some return values we can use void for those return 
values.

We can pass the return values to functions. We can write foo( foo(a, b) );

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.,

We cab do the following also
(c, d) == foo(a, b), (c, d) > foo(a, b) etc.,

(a, b) = (b, a) swaps the values. It should generate the code equivalent to

(float; int) dummy(float b, int a) {
     return (b, a);
}
(a, b) = dummy(b, a);

Move semantics can be used to assign. Hence we will not face the issue 
mentioned in N3538 document if there are no in out parameters.

There are some problem areas like type casting. Probably they can be 
prohibited. Other issues may remain and need to be discussed.

Probably multiple return values might have been discussed earlier. 
Nevertheless, I wanted to give it a shot.

-- 

--- 
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.



------=_Part_3796_26940885.1367244196978
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Problem:<div>Having a single return value means we have to pass the other r=
eturn values as parameters as a reference or a pointer. This makes the prog=
rams difficult to understand. Moreover we can solve most of the problems me=
ntioned in&nbsp;<a href=3D"http://www.open-std.org/JTC1/SC22/WG21/docs/pape=
rs/2013/n3538.html">http://www.openstd.org/JTC1/SC22/WG21/docs/papers/2013/=
n3538.html</a>.&nbsp;</div><div><br></div><div>Solution:</div><div>(int; fl=
oat) foo (int);</div><div>Probably a contextual keyword returns can be adde=
d to specify that the first pair of parentheses represents return values. S=
o we will be passing only in parameters and in out parameters to the functi=
on. All the out parameters are only returned.</div><div><br></div><div>With=
 this we can write the code</div><div><br></div><div>int a;</div><div>float=
 b;</div><div>(a; b) =3D foo(a, b);</div><div>(int c; float d) =3D foo(a, b=
);</div><div><br></div><div>If foo returns int &amp; instead of int then we=
 need to write</div><div><br></div><div>(int &amp;c; float d) =3D foo(a, b)=
;</div><div><br></div><div>If we decide to ignore some return values we can=
 use void for those return values.</div><div><br></div><div>We can pass the=
 return values to functions. We can write foo( foo(a, b) );</div><div><br><=
/div><div>We can compare the return values. The semantics can be defined as=
 the operation should be true for all the return values.</div><div>foo(a, &=
nbsp;b) =3D=3D foo(c, d), foo(a, b) &gt;=3D foo(c, d) etc.,<br></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><div><br></div><div>(a, b) =3D (b, a) s=
waps the values. It should generate the code equivalent to</div><div><br></=
div><div>(float; int) dummy(float b, int a) {</div><div>&nbsp; &nbsp; &nbsp=
;return (b, a);</div><div>}</div><div>(a, b) =3D dummy(b, a);</div><div><br=
></div><div>Move semantics can be used to assign. Hence we will not face th=
e issue mentioned in N3538 document if there are no in out parameters.</div=
><div><br></div><div>There are some problem areas like type casting. Probab=
ly they can be prohibited. Other issues may remain and need to be discussed=
..</div><div><br></div><div>Probably multiple return values might have been =
discussed earlier. Nevertheless, I wanted to give it a shot.</div><div><br>=
</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 />

------=_Part_3796_26940885.1367244196978--

.
