220 19927 <b003ffb3-2f0b-4c41-8db0-0a57743e5d93@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Arthur Tchaikovsky <atch.cpp@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: default arguments
Date: Wed, 19 Aug 2015 09:27:09 -0700 (PDT)
Lines: 187
Approved: news@gmane.org
Message-ID: <b003ffb3-2f0b-4c41-8db0-0a57743e5d93@isocpp.org>
References: <ef9c7cbe-e8f1-4196-83bc-11a1c9b2798c@isocpp.org>
 <CANh8DEnn-PWZRNUvqhjcaJpiZk+6hyxVpy5qQXgTUw-uMhdh1A@mail.gmail.com>
 <ccf43684-c479-420e-a6b2-5a23673f7c5a@isocpp.org>
 <89bf9d09-00ed-45db-bf88-39c844707bd1@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_458_1030215788.1440001629518"
X-Trace: ger.gmane.org 1440001648 5661 80.91.229.3 (19 Aug 2015 16:27:28 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 19 Aug 2015 16:27:28 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDL6FI4NYYERBXW42KXAKGQEKDXAVXY@isocpp.org Wed Aug 19 18:27:16 2015
Return-path: <std-proposals+bncBDL6FI4NYYERBXW42KXAKGQEKDXAVXY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vk0-f69.google.com ([209.85.213.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDL6FI4NYYERBXW42KXAKGQEKDXAVXY@isocpp.org>)
	id 1ZS6Cm-0003qT-En
	for gclcip-std-proposals@m.gmane.org; Wed, 19 Aug 2015 18:27:12 +0200
Original-Received: by vkm66 with SMTP id 66sf8579471vkm.1
        for <gclcip-std-proposals@m.gmane.org>; Wed, 19 Aug 2015 09:27: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
         :content-type:x-original-sender:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=CPbC7VP75RRK4WJ0vC/kYjmvBWmLs731xPJ3TnXmK1E=;
        b=ZAqx+8xPAuNpVc5ACnPFADSspVFVwRGyxkVG0CP+loZvw11J3BXRe64LxWeJbZk1D2
         4h51TmOw6+jZCVVkykEkIpC8B7eHX6MThiDXqle5iOr7ql4j8zKr7D4vpOP4byQH7S/J
         1MV0q+vp3DDAkJU07u1AJ+q/qLHfNeRaGLYPBPcOhpak6qsDHZ5ICFU9dQzNH86B11wA
         nq5Vss0Rs4bFXklGjyjPhVonAYOomSt7r76bz58sh/Wn1gog1UZS7AGwsBVRQqs+0KLZ
         xNGi+bmeuHcFjPMLF0Wa6ynb+zoLWQI//F7TxbhWTFdcIxnAmbtCTWk4FomAxRuBCBoA
         YX4g==
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:content-type:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=CPbC7VP75RRK4WJ0vC/kYjmvBWmLs731xPJ3TnXmK1E=;
        b=kZoRCypG3YYUFLn1R1ZeoJzpMQOf4uwOtuqz1RgKFkZV2ROF2axbqU3DEjxjJV3qB0
         CvqG2xvmlPE6xhq66azPRzEDz6GLDx8mWn3ru40UQImxGG+k9nhcakEVJr6XPKz+QF0L
         +DhpibpzT7mT0lJCFf2GaEIiFAXws0Ygm1Cd+3SJmR4FNOHppreZS6Ze1UHzZIdOjoMe
         jyaiSZd1LV9ts1HWhgBlwbeo/MNep0NKZvygUy/HuVWbE+D1A15W1+a6xHjWs3z22ime
         279g2yy/vbCkchyDd+E/HccF5SEJKlyZKPW4jIHBJMaLgX7sTtoBcJ3m5ScGB4XwI4To
         hp2Q==
X-Gm-Message-State: ALoCoQntRab49g7pypoPQ4jPVkRICqEZZz+HneoLoLM6nVKY2ZoPABUdrJSpbmzWO3tLL+QkRoIT
X-Received: by 10.140.147.151 with SMTP id 145mr11073578qht.5.1440001631416;
        Wed, 19 Aug 2015 09:27:11 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.86.210 with SMTP id p76ls211260qgd.31.gmail; Wed, 19 Aug
 2015 09:27:10 -0700 (PDT)
X-Received: by 10.140.27.161 with SMTP id 30mr173503qgx.10.1440001630276;
        Wed, 19 Aug 2015 09:27:10 -0700 (PDT)
In-Reply-To: <89bf9d09-00ed-45db-bf88-39c844707bd1@isocpp.org>
X-Original-Sender: atch.cpp@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:19927
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19927>

------=_Part_458_1030215788.1440001629518
Content-Type: multipart/alternative; 
	boundary="----=_Part_459_863877001.1440001629519"

------=_Part_459_863877001.1440001629519
Content-Type: text/plain; charset=UTF-8

It *is not* simpler. What you've just shown is a violation of 
encapsulation. Not simplification.

On Wednesday, 19 August 2015 16:08:52 UTC+1, S.B. wrote:
>
> It's even simpler if we could write 
>
> struct s {
>     int a = 1337;
>     int b = 4096;
> };
>  
> int main() {
>     s x;
>     s y { 42 }; // or s y { .a = 42 };
>     s z { .b = 42 };
>     return 0;
> }
>
> :)
>
> On Wednesday, August 19, 2015 at 2:02:01 PM UTC+8, Max Truxa wrote:
>>
>> I have to agree with Matt Calabrese completely. As it was already 
>> asserted named arguments are not going to happen anytime soon (if at all).
>>
>> Earlier in this thread there were workarounds listed which are more or 
>> less comparable to the proposal in their effect.
>> I would like to elaborate some more on one of these workarounds, as it 
>> can be mapped pretty much 1-to-1 to the proposal and it happens to be the 
>> solution I employ when encountering this kind of problem.
>>
>>
>> # Current workaround.
>>
>> struct s {
>>     static int const default_a = 1337;
>>     static int const default_b = 4096;
>>     s(int a = default_a, int b = default_b) 
>>         : a(a), b(b) { }
>>     int a;
>>     int b;
>> };
>>  
>> int main() {
>>     s x;
>>     s y(42);
>>     s z(s::default_a, 42);
>>     return 0;
>> }
>>
>> See working code here: http://ideone.com/OKtbuc
>>
>>
>> # Using the proposed syntax.
>>
>> struct s {
>>     s(int a = 1337, int b = 4096) 
>>         : a(a), b(b) { }
>>     int a;
>>     int b;
>> };
>>  
>> int main() {
>>     s x;
>>     s y(42);
>>     s z(default, 42);
>>     return 0;
>> }
>>
>> The current solution has a number of drawbacks.
>> 1) It's unnecessarily verbose.
>> 2) It's easy to mess up for parameters that have the same type. (`s 
>> z(s::default_b, 42)` - Oops, passed `default_b` as `a`.)
>> 3) When looking up the actual default values there is one more hop to 
>> make. It's not sufficient to look at the function declaration but 
>> additionally we have to look for e.g. default_a.
>>
>>

-- 

--- 
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/.

------=_Part_459_863877001.1440001629519
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">It *is not* simpler. What you&#39;ve just shown is a viola=
tion of encapsulation. Not simplification.<br><br>On Wednesday, 19 August 2=
015 16:08:52 UTC+1, S.B.  wrote:<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">It&#39;s even simpler if we could write <br><br><div sty=
le=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);borde=
r-style:solid;border-width:1px;word-wrap:break-word"><code><div><span style=
=3D"color:#008">struct</span><span style=3D"color:#000"> s </span><span sty=
le=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </sp=
an><span style=3D"color:#008">int</span><span style=3D"color:#000"> a </spa=
n><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><=
span style=3D"color:#066">1337</span><span style=3D"color:#660">;</span><sp=
an style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span style=3D"color:#008"=
>int</span><span style=3D"color:#000"> b </span><span style=3D"color:#660">=
=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#066">409=
6</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br><=
/span><span style=3D"color:#660">};</span><span style=3D"color:#000"><br>=
=C2=A0<br></span><span style=3D"color:#008">int</span><span style=3D"color:=
#000"> main</span><span style=3D"color:#660">()</span><span style=3D"color:=
#000"> </span><span style=3D"color:#660">{</span><span style=3D"color:#000"=
><br>=C2=A0 =C2=A0 s x</span><span style=3D"color:#660">;</span><span style=
=3D"color:#000"><br>=C2=A0 =C2=A0 s y </span><span style=3D"color:#660">{</=
span><span style=3D"color:#000"> </span><span style=3D"color:#066">42</span=
><span style=3D"color:#000"> </span><span style=3D"color:#660">};</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#800">// or s y { .a =
=3D 42 };</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 s z </span><sp=
an style=3D"color:#660">{</span><span style=3D"color:#000"> </span><span st=
yle=3D"color:#660">.</span><span style=3D"color:#000">b </span><span style=
=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=3D=
"color:#066">42</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">};</span><span style=3D"color:#000"><br>=C2=A0 =C2=A0 </span><span=
 style=3D"color:#008">return</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#066">0</span><span style=3D"color:#660">;</span><span styl=
e=3D"color:#000"><br></span><span style=3D"color:#660">}</span></div></code=
></div><br>:)<br><br>On Wednesday, August 19, 2015 at 2:02:01 PM UTC+8, Max=
 Truxa wrote:<blockquote class=3D"gmail_quote" style=3D"margin:0;margin-lef=
t:0.8ex;border-left:1px #ccc solid;padding-left:1ex">I have to agree with M=
att Calabrese completely. As it was already asserted named arguments are no=
t going to happen anytime soon (if at all).<p>Earlier in this thread there =
were workarounds listed which are more or less comparable to the proposal i=
n their effect.<br>I would like to elaborate some more on one of these work=
arounds, as it can be mapped pretty much 1-to-1 to the proposal and it happ=
ens to be the solution I employ when encountering this kind of problem.</p>=
<p><br># Current workaround.</p><p>struct s {<br>=C2=A0 =C2=A0 static int c=
onst default_a =3D 1337;<br>=C2=A0 =C2=A0 static int const default_b =3D 40=
96;<br>=C2=A0 =C2=A0 s(int a =3D default_a, int b =3D default_b) <br>=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 : a(a), b(b) { }<br>=C2=A0 =C2=A0 int a;<br>=C2=A0 =
=C2=A0 int b;<br>};<br>=C2=A0<br>int main() {<br>=C2=A0 =C2=A0 s x;<br>=C2=
=A0 =C2=A0 s y(42);<br>=C2=A0 =C2=A0 s z(s::default_a, 42);<br>=C2=A0 =C2=
=A0 return 0;<br>}</p><p>See working code here: <a href=3D"http://ideone.co=
m/OKtbuc" rel=3D"nofollow" target=3D"_blank" onmousedown=3D"this.href=3D&#3=
9;http://www.google.com/url?q\75http%3A%2F%2Fideone.com%2FOKtbuc\46sa\75D\4=
6sntz\0751\46usg\75AFQjCNFJTtR-2NKU_hCXpY0qHPmkHWZV9g&#39;;return true;" on=
click=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3A%2F%2Fideone=
..com%2FOKtbuc\46sa\75D\46sntz\0751\46usg\75AFQjCNFJTtR-2NKU_hCXpY0qHPmkHWZV=
9g&#39;;return true;">http://ideone.com/OKtbuc</a></p><p><br># Using the pr=
oposed syntax.</p><p>struct s {<br>=C2=A0 =C2=A0 s(int a =3D 1337, int b =
=3D 4096) <br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 : a(a), b(b) { }<br>=C2=A0 =C2=A0=
 int a;<br>=C2=A0 =C2=A0 int b;<br>};<br>=C2=A0<br>int main() {<br>=C2=A0 =
=C2=A0 s x;<br>=C2=A0 =C2=A0 s y(42);<br>=C2=A0 =C2=A0 s z(default, 42);<br=
>=C2=A0 =C2=A0 return 0;<br>}</p><p>The current solution has a number of dr=
awbacks.<br>1) It&#39;s unnecessarily verbose.<br>2) It&#39;s easy to mess =
up for parameters that have the same type. (`s z(s::default_b, 42)` - Oops,=
 passed `default_b` as `a`.)<br>3) When looking up the actual default value=
s there is one more hop to make. It&#39;s not sufficient to look at the fun=
ction declaration but additionally we have to look for e.g. default_a.</p><=
p></p><p></p><p></p><p></p><p></p><p></p></blockquote></div></blockquote></=
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_459_863877001.1440001629519--
------=_Part_458_1030215788.1440001629518--

.
