220 41117 <CAB+4KHLe6zDPRreF2q0zQptUgrO0-_u8VrAOA7Du+_KHxhGUnw@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Andrew Tomazos <andrewtomazos@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Function Parameter of Struct Type -> Named Parameters
Date: Thu, 29 Nov 2018 14:57:55 +1000
Lines: 118
Approved: news@gmane.org
Message-ID: <CAB+4KHLe6zDPRreF2q0zQptUgrO0-_u8VrAOA7Du+_KHxhGUnw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="0000000000005b3a27057bc68741"
X-Trace: blaine.gmane.org 1543467364 24060 195.159.176.226 (29 Nov 2018 04:56:04 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 29 Nov 2018 04:56:04 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBD5KHQXXWYPRBYPD7XPQKGQEQS2Y64Y@isocpp.org Thu Nov 29 05:56:00 2018
Return-path: <std-proposals+bncBD5KHQXXWYPRBYPD7XPQKGQEQS2Y64Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lj1-f198.google.com ([209.85.208.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBD5KHQXXWYPRBYPD7XPQKGQEQS2Y64Y@isocpp.org>)
	id 1gSEMq-00068Q-6f
	for gclcip-std-proposals@m.gmane.org; Thu, 29 Nov 2018 05:56:00 +0100
Original-Received: by mail-lj1-f198.google.com with SMTP id t7-v6sf227556ljg.9
        for <gclcip-std-proposals@m.gmane.org>; Wed, 28 Nov 2018 20:58:11 -0800 (PST)
ARC-Seal: i=2; a=rsa-sha256; t=1543467490; cv=pass;
        d=google.com; s=arc-20160816;
        b=WZDWyAZopHuYTLcYY/QO/qr9uyLdFNRbCyAS8VBGVL3tHXl0/QVEQ6afA3IWD1n9Qo
         A1hAYdGet2/K6rdFaGARQxLbBCNpftJxMiQPdq2d0LR1LwykfcpP9J/ppW+whVH4YeLk
         9Jr30xkIjY4reY+IS8OkvPqdD5PCpzxXOzCrTlSWkMOzH+DGCHgajAMghqg8g+V7voj1
         BxEY0i9iuEOib3k5IbCRpzhZI847+RThkPW75fsJ3Kps3cCP6ZPYlZ+pnSTYILjMuXSo
         8LtenvQNoDfujZJsba4emHQZRhG0+ZcYe+Oyvpeg97BY6EYGCYSXmV4TIax9XGbd7N5D
         A32g==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:to:subject:message-id:date
         :from:mime-version:dkim-signature;
        bh=w2H00hFuIWMwMYnNxBta9BsBHtBiQ5N+rvweldBlwMA=;
        b=n4AXBzZ29t7rs3zOvGmhhp/21FeZ0lG9Ae9VXtnCSgooQh3lN1sPj8OrSAJ6JPVvrW
         IBkGC/tuqHX1nVMFnr1wifIKdH4PdnWEg44P+TSpazwc1KHqAQQwU2J5q8FX7iteqOz7
         Z+Cha4zFyvHXFPorvjBvissV71gp4ZY4ATODM6af9ntWdH6fJXaPYvO4OUWSMcrjpw0b
         owhM2YzPFs8Ryg1JDTnFOCamCQ95jHmqkI+/b6lkQ4ZkP8jrPHLZcMYq+Kt6TdtpSCAG
         sTzELdYuHzklFSXYj7XtwhmuKj5DUMr17cXL6meOJBgqBSkyDwjc9aIxL+ku336eEXE3
         KQng==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=ShDZJnxY;
       spf=pass (google.com: domain of andrewtomazos@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=andrewtomazos@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:from:date:message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=w2H00hFuIWMwMYnNxBta9BsBHtBiQ5N+rvweldBlwMA=;
        b=o3hQv1x/2/HTZ/no214GbK2MJALzUOYoQL1X+YWx2MJoUSUVaYPJ7/nnNlRftZvCJU
         nkTnHMrBgJsmfnG2QR6IJwx9WXpVRoG4jWtgpiiOzrAoLrsJCHM2O2ZHNQxZSk/vdhog
         DQgoINdq/1iqX8ceAt6J9D7Qlh7bLqfVK0z2iRpW3Utqa0WVhcdi0KP4EHrx5G7TxYbN
         HNu47CJceBaixR0BEVC7UFG3vp/wodI1b6o6ADhe967AV0xG4Z5qj8u5aD5ZGc7aRvP0
         4zJQbfA3TT0OSWEs0+usQJJmKBJoTe2Xstg+u8wex6En7JVnbB+FnBLrRB882HZe5AQe
         0mow==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:from:date:message-id:subject:to
         :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=w2H00hFuIWMwMYnNxBta9BsBHtBiQ5N+rvweldBlwMA=;
        b=JKWLLeX4YuPpEKoj9V4wuogSXp7Utsy13ncSOufku8RAWdxmUs7gE1yy86r/YymN6r
         +0SMaYC/kOfBINwICyETwO9OKEqB3EJhxzz8X/MV8SB29KOblIVVNkxRqRZwhRxiVLp+
         q3DyGX+bn5caD/+EDDQNZaRino0G+RHWtbvCuSPWY1eK8HwLEpA5QO5AbR1cGLEz+Vtr
         WQmf8I3ePrIfcuVUAvCpuKE0amFCbISqZG0aIwVJWN73x8sdC1X1Nak707oSFYuS0FFo
         o4q8Vo4og3QHAcp78zyXW2RPFsJeCjf0G6Ad0Zd+USLBiqLYLjqatwg621/XidHp09sd
         Tr2g==
X-Gm-Message-State: AA+aEWYepk1xqRRr3aa8w5tzprP2L1oh/mGzhOtrDwoRA9x0QH1ebe9Z
	9NCmybA3MVHxsF9VBbUdwkCbqQ==
X-Google-Smtp-Source: AFSGD/WnzI4/xWzuuxuU55r/39me+Ginup0WzB2XuV78A1i3J0JNj2F/XTaDOo1nzpFaZk0wP2RIbQ==
X-Received: by 2002:a19:740a:: with SMTP id v10mr5002lfe.16.1543467490807;
        Wed, 28 Nov 2018 20:58:10 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a19:3fc4:: with SMTP id m187ls38125lfa.1.gmail; Wed, 28 Nov
 2018 20:58:08 -0800 (PST)
X-Received: by 2002:a19:2584:: with SMTP id l126mr23659lfl.69.1543467488954;
        Wed, 28 Nov 2018 20:58:08 -0800 (PST)
ARC-Seal: i=1; a=rsa-sha256; t=1543467488; cv=none;
        d=google.com; s=arc-20160816;
        b=GduJKm1STKWnSEmyKw7bcU3i9Op4d4UjhqA6Ey5HZLJ7E83jVakf0Yn1/8yvuC7WUt
         6+yLkqAa4YDza/H7VAZZxn3mMd2MNOeN5eQUUVY62qsLwoIJ6MlUjzUlx9N57lQHztIl
         FFfhdqs4H5VAWHw5YlKh8Sjj/1j86VsDPcwVGjLY0/vrd38dNI0Yx+SisCVYXl4QOgWm
         0cCwOzfye7CjJxx978jHTXKLvXYtSqp8bWffWXV8LIyKKYmwOtwvENN5IK3UYq4Nsvsj
         bM/VhkVrI5H2odIJW0mvUopvuDpD7PVq8HYmURM1bnB91IT/shOYndGLLS1n947/RNr4
         w3rA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:mime-version:dkim-signature;
        bh=WRNnM9AoCKqIb7RFb/LDug2YXxeAWr4p4JBGmwK15zM=;
        b=XnqGexrU+eSIpFhrUBK/EN/NKjXHYjfl8+wChXrCjwpVe5n/UNVuPvvtURZzsxpg+m
         5GrBNB2FJDuNbKd/exU+NSSRRUtW+RDxvUyJksJllbE4qT5im/wpEglv/drhBdiOqYG9
         u07m+xzKh+oK4eCYVlXKWtJLqoiKSq2slomht6+KPPh4+G+lh6WfF6ONOsEufgveWLnY
         WEdRibN5+LRJsV6ucfyWGtMnD5rftYj3YYwGvlEI2x3jYYd6E/xA5QZOtz/m+OJbsxaB
         iODDvkPOLaliiTYeW+0PpDghgk2bru9DWwQulCF1vcxxoWNGOQx8mnzW4KkVKDVCUIir
         hqew==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=ShDZJnxY;
       spf=pass (google.com: domain of andrewtomazos@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=andrewtomazos@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Original-Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
        by mx.google.com with SMTPS id o26-v6sor353410ljj.36.2018.11.28.20.58.08
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Wed, 28 Nov 2018 20:58:08 -0800 (PST)
Received-SPF: pass (google.com: domain of andrewtomazos@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Received: by 2002:a2e:9f0b:: with SMTP id u11-v6mr21572ljk.99.1543467488195;
 Wed, 28 Nov 2018 20:58:08 -0800 (PST)
X-Original-Sender: andrewtomazos@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.s=20161025 header.b=ShDZJnxY;       spf=pass
 (google.com: domain of andrewtomazos@gmail.com designates 209.85.220.41 as
 permitted sender) smtp.mailfrom=andrewtomazos@gmail.com;       dmarc=pass
 (p=NONE sp=QUARANTINE 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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://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>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:41117
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/41117>

--0000000000005b3a27057bc68741
Content-Type: text/plain; charset="UTF-8"

It seems to me that a function that takes a struct combined with C++20
designated initializers gets us very close to named parameters:

struct FooParameters {
    int bar;
    float baz;
};
float foo(FooParameters params) {
   return (params.bar + 3) * params.baz;
}
int main() {
   foo({bar: 4, baz: 3.2});
}

If we added some syntactic sugar that...
1. Removed the need to give the parameter struct type a name
2. Introduced the parameter struct members into the function definition
scope.

....we would get pretty close:

float foo(struct { int bar; float baz }) {
    return (bar + 3) * baz;
}
int main() {
   foo({bar: 4, baz:3.2});
}

I'd need to take a look to see if it is ambiguous, but I think we can drop
the struct keyword from the above:

float foo({int bar; float baz}) {
    return (bar + 3) * baz;
}
int main() {
   foo({bar: 4, baz:3.2});
}

This would be equivalent to:

struct __A { int bar; float baz };
float foo(__A __a) {
   auto&& [bar,baz] = __a;
    return (bar + 3) * baz;
}
int main() {
   foo({bar: 4, baz:3.2});
}

From a teachability perspective its pretty easy to explain that "a
brace-enclosed function parameter is the body of an anonymous struct, the
members of which are introduced into the function definition scope."

This also seems easy to implement.

Thoughts?  Worth pursuing?

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAB%2B4KHLe6zDPRreF2q0zQptUgrO0-_u8VrAOA7Du%2B_KHxhGUnw%40mail.gmail.com.

--0000000000005b3a27057bc68741
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">It seems to me that a function that takes a struct combine=
d with C++20 designated initializers gets us very close to named parameters=
:<div><br></div><div>struct FooParameters {</div><div>=C2=A0 =C2=A0 int bar=
;</div><div>=C2=A0 =C2=A0 float baz;</div><div>};</div><div>float foo(FooPa=
rameters params) {</div><div>=C2=A0 =C2=A0return (params.bar=C2=A0+ 3) * pa=
rams.baz;</div><div>}</div><div>int main() {</div><div>=C2=A0 =C2=A0foo({ba=
r: 4, baz: 3.2});</div><div>}</div><div><br></div><div>If we added some syn=
tactic sugar that...</div><div>1. Removed the need to give the parameter st=
ruct type a name</div><div>2. Introduced the parameter struct members into =
the function definition scope.</div><div><br></div><div>...we would get pre=
tty close:</div><div><br></div><div>float foo(struct { int bar; float baz }=
) {</div><div>=C2=A0 =C2=A0 return (bar=C2=A0+ 3) * baz;</div><div>}</div><=
div>int main() {</div><div>=C2=A0 =C2=A0foo({bar: 4, baz:3.2});</div><div>}=
</div><div><br></div><div>I&#39;d need to take a look to see if it is ambig=
uous, but I think we can drop the struct keyword from the above:</div><div>=
<br></div><div><div>float foo({int bar; float baz}) {</div><div>=C2=A0 =C2=
=A0 return (bar=C2=A0+ 3) * baz;</div><div>}</div><div>int main() {</div><d=
iv>=C2=A0 =C2=A0foo({bar: 4, baz:3.2});</div><div>}</div><br class=3D"gmail=
-Apple-interchange-newline"></div><div>This would be equivalent to:</div><d=
iv><br></div><div>struct __A { int bar; float baz };</div><div>float foo(__=
A __a) {</div><div>=C2=A0 =C2=A0auto&amp;&amp; [bar,baz] =3D __a;</div><div=
><div>=C2=A0 =C2=A0 return (bar=C2=A0+ 3) * baz;</div></div><div>}</div><di=
v><div>int main() {</div><div>=C2=A0 =C2=A0foo({bar: 4, baz:3.2});</div><di=
v>}</div></div><div><br></div><div>From a teachability perspective its pret=
ty easy to explain that &quot;a brace-enclosed function parameter is the bo=
dy of an anonymous struct, the members of which are introduced into the fun=
ction definition scope.&quot;</div><div><br></div><div>This also seems easy=
 to implement.</div><div><br></div><div>Thoughts?=C2=A0 Worth pursuing?</di=
v><div><br></div></div>

<p></p>

-- <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 />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAB%2B4KHLe6zDPRreF2q0zQptUgrO0-_u8Vr=
AOA7Du%2B_KHxhGUnw%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAB%2B4KHLe6z=
DPRreF2q0zQptUgrO0-_u8VrAOA7Du%2B_KHxhGUnw%40mail.gmail.com</a>.<br />

--0000000000005b3a27057bc68741--

.
