220 11460 <a36b1035-fabd-402f-9817-498acd56e614@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Matthew Fioravante <fmatthew5876@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Named function parameters using anonymous structs
 for C and C++
Date: Mon, 16 Jun 2014 19:46:10 -0700 (PDT)
Lines: 299
Approved: news@gmane.org
Message-ID: <a36b1035-fabd-402f-9817-498acd56e614@isocpp.org>
References: <72c49240-547b-4bf6-8b27-aff6a61c1272@isocpp.org> <cb957c9d-f151-4cdb-b749-c3e158d72e3c@isocpp.org> <ea5e7788-1c8f-43e6-9486-5fec31b22166@isocpp.org> <ce610dc2-be04-4f15-813b-f8aaa55aab63@isocpp.org> <D251F8E8-26EA-46C8-A6FC-877748BB4E46@gmail.com>
 <36D3B24B-7F24-4ED5-A27C-F4EF71CF244C@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_2016_7386306.1402973170506"
X-Trace: ger.gmane.org 1402973180 13129 80.91.229.3 (17 Jun 2014 02:46:20 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 17 Jun 2014 02:46:20 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDELF54RTIGRB46X72OAKGQE54RR43Y@isocpp.org Tue Jun 17 04:46:13 2014
Return-path: <std-proposals+bncBDELF54RTIGRB46X72OAKGQE54RR43Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oa0-f69.google.com ([209.85.219.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDELF54RTIGRB46X72OAKGQE54RR43Y@isocpp.org>)
	id 1WwjPY-0004FU-JT
	for gclcip-std-proposals@m.gmane.org; Tue, 17 Jun 2014 04:46:12 +0200
Original-Received: by mail-oa0-f69.google.com with SMTP id j17sf37646277oag.4
        for <gclcip-std-proposals@m.gmane.org>; Mon, 16 Jun 2014 19:46:11 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:message-id:in-reply-to:references:subject:mime-version
         :x-original-sender:reply-to:precedence:mailing-list:list-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=qwTuN0CN/99ouxHWVfdhdoB1eZMtzaf2iQOps/uMXJQ=;
        b=IHUZTNAKk9BApx5iRs471L0pbrpkFiG+tjAH359+vuNOzixQAgJxk+SXIPcjDuTFUK
         mUmGdnvzcMRBJuRj/MX4rwKLziNSzQVaGRRyvlqCMMLCsmz0mPhowOjobVhbB5/MjPZR
         7T6XxJNd5LGpDur1uNwK8DJZUJmj1bFT9wHCIlLhprQrw7QAEToSLzweJJgN9t2bMI+q
         JZXOswzuDBnk5ExVz48vy6/hRqhLCd39z9CPfUgRLUH1pQa3O3/W3EuslTRqFtR/y+wG
         q+a6ERtl1CQaRq8lbL1cPCnCF7gt4mu8PHeBi3qcJhrAa1bB7dGPvCUUWu+FLttycRcY
         ARMQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:x-original-sender:reply-to:precedence
         :mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=qwTuN0CN/99ouxHWVfdhdoB1eZMtzaf2iQOps/uMXJQ=;
        b=EExViu+EpUcFFhuMj6gQ9sXsZV+BgUmTp5J/EJ+q8qctWOGVD9CVUdUMm3aSoT7cA7
         oDlCUh+BCxQROYB/Q++7Tor2zRYGopu7W3yo2yiP9erEWZjFlc3Lqyzqh/4UIvlOI1IB
         PzZ3e0W0vcC24QUvSSwUfmBsPhPEpgqPH3cZwgsihv2lM2HpSv0j3Wgx0pyMovB/Ktgr
         l5gAIOauNNzeORDezOgsj2CjFuCGKtWPBgSNRWbvVUMn4jxVy6gEF0A+kB9KhhRioVt8
         v+SdzAPnhdKboHlSabOwa1muPmu76n4brPR37ygQdh7EWeRfzLUAcEIZlLBio0F1900c
         UZuw==
X-Gm-Message-State: ALoCoQmRHxcCmKEZE3igf+Rv8ru+y/wa5UhZZpopjkf7wSAFJOEYiX7MkocAdryactn05NiAKITe
X-Received: by 10.50.56.74 with SMTP id y10mr561516igp.3.1402973171609;
        Mon, 16 Jun 2014 19:46:11 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.25.225 with SMTP id 88ls560540qgt.85.gmail; Mon, 16 Jun
 2014 19:46:11 -0700 (PDT)
X-Received: by 10.140.80.5 with SMTP id b5mr1724qgd.20.1402973171075;
        Mon, 16 Jun 2014 19:46:11 -0700 (PDT)
In-Reply-To: <36D3B24B-7F24-4ED5-A27C-F4EF71CF244C@gmail.com>
X-Original-Sender: fmatthew5876@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:11460
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/11460>

------=_Part_2016_7386306.1402973170506
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Monday, June 16, 2014 9:52:38 PM UTC-4, David Krauss wrote:
>
>
> On 2014=E2=80=9306=E2=80=9317, at 9:37 AM, David Krauss <pot...@gmail.com=
 <javascript:>>=20
> wrote:
>
>
> On 2014=E2=80=9306=E2=80=9317, at 5:43 AM, corentin....@cea.fr <javascrip=
t:> wrote:
>
> Le lundi 16 juin 2014 21:18:52 UTC+2, Matthew Fioravante a =C3=A9crit :
>>
>> That also implies adding support for C tagged structure initialization t=
o=20
>> C++, which implies defining how it works with constructors. At first pas=
s,=20
>> I'd say only enable the syntax for POD structs. This would need to be=20
>> studied very carefully. I wouldn't be surprised if this was already brou=
ght=20
>> up in the past, studied, and rejected for some reason. Does anyone have=
=20
>> insight on that? Google doesn't appear to be helpful.
>>
>
> A proposal has been written recently:
>
> https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/IgDFqKjK=
lRs/CGARpDJy9JsJ=20
> I do not know what is the current status of that proposal though.
>
>
> It would probably be better to make a clean start, based on review of=20
> discussions on this forum.
>
> Note, I was advocating the designated initializer solution earlier in thi=
s=20
> thread but nobody seemed to care at the time. Anyone who=E2=80=99s intere=
sted might=20
> check those posts.
>
>
> Oh, it was the other thread. And my strongest point was that, even if=20
> named parameters are implemented separately from pass-by-struct, folks wi=
ll=20
> still combine designated initializers with pass-by-struct anyway. This=20
> results in two similar ways of doing the same thing, which should have=20
> similar if not same syntax.
>

I completely agree with you that we must reuse designated initializer=20
syntax. Having 2 different syntax just complicates the language. Its=20
completely necessary. There's no bike shed to be painted here!
=20

> =20
>

> This thread seems to be simply taking the alternative idea and running=20
> with it. :)
>
> One suggestion, but it=E2=80=99s only that: the struct is the sole argume=
nt, then=20
> allow designated initializer syntax directly in the argument list =E2=80=
=94 i.e.,=20
> allow brace elision.
>
> struct rect {
>     int top, left, bottom, right;
>
>     rect( /* struct */ { int in_top, in_left, in_bottom, in_right; } )
>         : top( in_top ), left( in_left ), bottom( in_bottom ), right(=20
> in_right ) {}
>
>     rect( /* struct */ { int in_top, in_left, in_height, in_width; } )
>         : top( in_top ), left( in_left )
>         , bottom( in_top + in_width ), right( in_left + in_width ) {}
> };
>
> rect a( .top =3D 4, .height =3D 43, .left =3D 10, .width =3D 100 );
> rect b( .top =3D 4, .bottom =3D 47, .left =3D 10, .right =3D 110 );
>
>
The original style:

int foo(int a, int b, string c);
foo(.a =3D 0, .b =3D 1, .c =3D "Hello");=20

Pros:
- Very simple
- No ABI changes
- All legacy code immediately becomes named function enabled
Cons:
- Cannot use named syntax when calling via a function pointer, since the=20
type has no concept of parameter names.
- Requires some language changes to enable the callsite syntax
- Argument names while not part of the ABI, are now part of the API. You=20
cannot change the names or you will break callers.=20
- All legacy code immediately becomes named function enabled.

The struct approach
int foo(int a, {int b; int c;}, }

Pros:
-Separates positional and named arguments. Is this desirable??
-No ABI changes again, just reuses the type system with anonymous structs
-Function pointers can also be name initialized when called, since their=20
type encodes the type of the struct, and the struct can be initialized=20
using tagged init syntax. This sounds like a big win.
-No special rules, all syntax inherited from struct
Cons;
-Functions with same arguments still have different types.
-Requires anonymous structs proposal
-If you have 2 overloads, with same positional arguments and different=20
structs, how do you choose which one to pick from initializer syntax?=20

void foo(int a, {int b; int c;});
void foo(int a, {string b=3D"", string c=3D""});

foo(1, {.c =3D "hello" });

I suppose the naming rule here could try to initialize each instance of foo=
=20
using the brace expression in order of appearance in an SFINAE like manner.


> I=E2=80=99d also help draft such a proposal if someone wants a collaborat=
or.=20
Right now I=E2=80=99m hoping to attend the November meeting > in Champaign,=
=20
although it=E2=80=99s not a guarantee and I might have a full plate with ot=
her=20
proposals. However, at this point a
> paper exploring the design space might be more appropriate than an=20
attempt at fully-baked wording, which reduces the=20
> burden of advocacy. There are a number of issues and corner cases to=20
check, and the committee needs to approve the=20
> =E2=80=9Cwhat=E2=80=9D before the =E2=80=9Chow.=E2=80=9D

Does it make sense to cram all of these sort of unrelated things into one=
=20
big proposal? Or do it incrementally with multiple proposals with the big=
=20
picture in mind?

I could start writing one or help with writing one and fleshing out the=20
details. It would be great to have someone actually present it at the=20
meetings, since I don't actually have the ability to attend myself.

--=20

---=20
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 e=
mail 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-proposa=
ls/.

------=_Part_2016_7386306.1402973170506
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Monday, June 16, 2014 9:52:38 PM UTC-4, David K=
rauss wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-lef=
t: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word=
-wrap:break-word"><br><div><div>On 2014=E2=80=9306=E2=80=9317, at 9:37 AM, =
David Krauss &lt;<a href=3D"javascript:" target=3D"_blank" gdf-obfuscated-m=
ailto=3D"ur3eSQj9Q7cJ" onmousedown=3D"this.href=3D'javascript:';return true=
;" onclick=3D"this.href=3D'javascript:';return true;">pot...@gmail.com</a>&=
gt; wrote:</div><br><blockquote type=3D"cite"><div style=3D"word-wrap:break=
-word"><br><div><div>On 2014=E2=80=9306=E2=80=9317, at 5:43 AM, <a href=3D"=
javascript:" target=3D"_blank" gdf-obfuscated-mailto=3D"ur3eSQj9Q7cJ" onmou=
sedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.href=3D'j=
avascript:';return true;">corentin....@cea.fr</a> wrote:</div><br><blockquo=
te type=3D"cite"><div dir=3D"ltr">Le lundi 16 juin 2014 21:18:52 UTC+2, Mat=
thew Fioravante a =C3=A9crit&nbsp;:<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">That also implies adding support for C tagged structure i=
nitialization to C++, which implies defining how it works with constructors=
.. At first pass, I'd say only enable the syntax for POD structs. This would=
 need to be studied very carefully. I wouldn't be surprised if this was alr=
eady brought up in the past, studied, and rejected for some reason. Does an=
yone have insight on that? Google doesn't appear to be helpful.</div></bloc=
kquote><div><br>A proposal has been written recently:<br><a href=3D"https:/=
/groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/IgDFqKjKlRs/CGARp=
DJy9JsJ" target=3D"_blank" onmousedown=3D"this.href=3D'https://groups.googl=
e.com/a/isocpp.org/forum/#!msg/std-proposals/IgDFqKjKlRs/CGARpDJy9JsJ';retu=
rn true;" onclick=3D"this.href=3D'https://groups.google.com/a/isocpp.org/fo=
rum/#!msg/std-proposals/IgDFqKjKlRs/CGARpDJy9JsJ';return true;">https://gro=
ups.google.com/a/<wbr>isocpp.org/forum/#!msg/std-<wbr>proposals/IgDFqKjKlRs=
/<wbr>CGARpDJy9JsJ</a> <br>I do not know what is the current status of that=
 proposal though.<br></div></div></blockquote><br></div><div>It would proba=
bly be better to make a clean start, based on review of discussions on this=
 forum.</div><br><div>Note, I was advocating the designated initializer sol=
ution earlier in this thread but nobody seemed to care at the time. Anyone =
who=E2=80=99s interested might check those posts.</div></div></blockquote><=
div><br></div><div>Oh, it was the other thread. And my strongest point was =
that, even if named parameters are implemented separately from pass-by-stru=
ct, folks will still combine designated initializers with pass-by-struct an=
yway. This results in two similar ways of doing the same thing, which shoul=
d have similar if not same syntax.</div></div></div></blockquote><div><br><=
/div><div><font size=3D"2">I completely agree with you that we must reuse d=
esignated initializer syntax. Having 2 different syntax just complicates th=
e language. Its completely&nbsp;</font>necessary<font size=3D"2">. There's =
no bike shed to be painted here!</font></div><div>&nbsp;</div><blockquote c=
lass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px=
 #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:break-word"><div><d=
iv><span style=3D"font-size: 13px;">&nbsp;</span></div></div></div></blockq=
uote><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8e=
x;border-left: 1px #ccc solid;padding-left: 1ex;"><div style=3D"word-wrap:b=
reak-word"><div><div><br></div><div>This thread seems to be simply taking t=
he alternative idea and running with it. :)</div><div><br></div><div>One su=
ggestion, but it=E2=80=99s only that: the struct is the sole argument, then=
 allow designated initializer syntax directly in the argument list =E2=80=
=94 i.e., allow brace elision.</div><div><br></div><div><font face=3D"Couri=
er">struct rect {</font></div><div><font face=3D"Courier">&nbsp; &nbsp; int=
 top, left, bottom, right;</font></div><div><font face=3D"Courier"><br></fo=
nt></div><div><font face=3D"Courier">&nbsp; &nbsp; rect( /* struct */ { int=
 in_top, in_left, in_bottom, in_right; } )</font></div><div><font face=3D"C=
ourier">&nbsp; &nbsp; &nbsp; &nbsp; : top( in_top ), left( in_left ), botto=
m( in_bottom ), right( in_right ) {}</font></div><div><font face=3D"Courier=
"><br></font></div><div><font face=3D"Courier">&nbsp; &nbsp; rect( /* struc=
t */ { int in_top, in_left, in_height, in_width; } )</font></div><div><font=
 face=3D"Courier">&nbsp; &nbsp; &nbsp; &nbsp; : top( in_top ), left( in_lef=
t )</font></div><div><font face=3D"Courier">&nbsp; &nbsp; &nbsp; &nbsp; , b=
ottom( in_top + in_width ), right( in_left + in_width ) {}</font></div><div=
><font face=3D"Courier">};</font></div><div><font face=3D"Courier"><br></fo=
nt></div><div><font face=3D"Courier">rect a( .top =3D 4, .height =3D 43, .l=
eft =3D 10, .width =3D 100 );</font></div><div><div><font face=3D"Courier">=
rect b( .top =3D 4, .bottom =3D 47, .left =3D 10, .right =3D 110 );</font><=
/div><div><br></div></div></div></div></blockquote><div><br></div><div>The =
original style:</div><div><br></div><div>int foo(int a, int b, string c);</=
div><div>foo(.a =3D 0, .b =3D 1, .c =3D "Hello");&nbsp;</div><div><br></div=
><div>Pros:</div><div>- Very simple</div><div>- No ABI changes</div><div>- =
All legacy code immediately becomes named function enabled</div><div>Cons:<=
/div><div>- Cannot use named syntax when calling via a function pointer, si=
nce the type has no concept of parameter names.</div><div>- Requires some l=
anguage changes to enable the callsite syntax</div><div>- Argument names wh=
ile not part of the ABI, are now part of the API. You cannot change the nam=
es or you will break callers.&nbsp;</div><div>- All legacy code immediately=
 becomes named function enabled.</div><div><br></div><div>The struct approa=
ch</div><div>int foo(int a, {int b; int c;}, }</div><div><br></div><div>Pro=
s:</div><div>-Separates positional and named arguments. Is this desirable??=
</div><div>-No ABI changes again, just reuses the type system with anonymou=
s structs</div><div>-Function pointers can also be name initialized when ca=
lled, since their type encodes the type of the struct, and the struct can b=
e initialized using tagged init syntax. This sounds like a big win.</div><d=
iv>-No special rules, all syntax inherited from struct</div><div>Cons;</div=
><div>-Functions with same arguments still have different types.</div><div>=
-Requires anonymous structs proposal</div><div>-If you have 2 overloads, wi=
th same positional arguments and different structs, how do you choose which=
 one to pick from initializer syntax?&nbsp;</div><div><br></div><div>void f=
oo(int a, {int b; int c;});</div><div>void foo(int a, {string b=3D"", strin=
g c=3D""});</div><div><br></div><div>foo(1, {.c =3D "hello" });</div><div><=
br></div><div>I suppose the naming rule here could try to initialize each i=
nstance of foo using the brace expression in order of appearance in an SFIN=
AE like manner.</div><div><br></div><div><br></div><div>&gt; I=E2=80=99d al=
so help draft such a proposal if someone wants a collaborator. Right now I=
=E2=80=99m hoping to attend the November meeting &gt; in Champaign, althoug=
h it=E2=80=99s not a guarantee and I might have a full plate with other pro=
posals. However, at this point a</div><div>&gt; paper exploring the design =
space might be more appropriate than an attempt at fully-baked wording, whi=
ch reduces the&nbsp;</div><div>&gt; burden of advocacy. There are a number =
of issues and corner cases to check, and the committee needs to approve the=
&nbsp;</div><div>&gt; =E2=80=9Cwhat=E2=80=9D before the =E2=80=9Chow.=E2=80=
=9D<br></div><div><br></div><div>Does it make sense to cram all of these so=
rt of unrelated things into one big proposal? Or do it incrementally with m=
ultiple proposals with the big picture in mind?<br></div><div><br></div><di=
v>I could start writing one or help with writing one and fleshing out the d=
etails. It would be great to have someone actually present it at the meetin=
gs, since I don't actually have the ability to attend myself.</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 />

------=_Part_2016_7386306.1402973170506--

.
