220 4098 <CAE1+XsYAmAD+OMxHSCT-+cn5=2dA-_SuiW8-2qZ3Z=cCabSiHA@mail.gmail.com> article
Path: news.gmane.org!not-for-mail
From: Hariharan Subramanian <tohari@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Default values in middle parameters in a function
Date: Tue, 30 Apr 2013 13:27:07 +0530
Lines: 166
Approved: news@gmane.org
Message-ID: <CAE1+XsYAmAD+OMxHSCT-+cn5=2dA-_SuiW8-2qZ3Z=cCabSiHA@mail.gmail.com>
References: <25d51458-9a2e-4607-9b1a-9d2a7be8df4e@isocpp.org>
	<CAGqM8fYDgZbfH6dugPnLqYvwZhSeVvC+gMVLLLx3OzYBmYByTg@mail.gmail.com>
	<CAE1+XsZWWbKwX+vJc7VQUjyRXXvmJePofKy2CP8+3ERRtTYrYw@mail.gmail.com>
	<7c79ca05-607f-40e8-bd51-467363f007ac@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=089e014939480adb8b04db8f5932
X-Trace: ger.gmane.org 1367308629 28883 80.91.229.3 (30 Apr 2013 07:57:09 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Tue, 30 Apr 2013 07:57:09 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCJZFFHTQQIBBVHS7WFQKGQEFUTOK5Y@isocpp.org Tue Apr 30 09:57:09 2013
Return-path: <std-proposals+bncBCJZFFHTQQIBBVHS7WFQKGQEFUTOK5Y@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ee0-f71.google.com ([74.125.83.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCJZFFHTQQIBBVHS7WFQKGQEFUTOK5Y@isocpp.org>)
	id 1UX5Qz-0003lL-9K
	for gclcip-std-proposals@m.gmane.org; Tue, 30 Apr 2013 09:57:09 +0200
Original-Received: by mail-ee0-f71.google.com with SMTP id c13sf311236eek.6
        for <gclcip-std-proposals@m.gmane.org>; Tue, 30 Apr 2013 00:57:09 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.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-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=VaGWs5I/CByHTMVw3wQ6EcXjKbV5o7ekR8U46LQj0GY=;
        b=AQIZPngUwr6YpiNwMqPwXMWYR+XKLl1KdXzVrFH1r4JKO0z8o1gzgq054E0BFUd3E/
         BtlUdDGIXqjt/Cu/82g82L4R+61k31Z4J488pDaRj7otso8qNHNufJ29RMXDgyC+sfX4
         1b69RNvosI+efCPb0wpTyjWz07aP4Zgeu4GrqgFPF3lQBdUSDeWYyFQA58jpj+RVKu3w
         nFayH+wzGxMn2E5XdS52NTQnrwFVLwqPHFs8umo6I4IDs2g7GQtaVO9HRfAxM23bzJJ9
         NYHfu9ajT7ezXVR5ekVLcTnP8qWnkyoCD4Rd3D3dQ9TnE/nslSz2SW3AUKnLgfSveRHU
  
X-Received: by 10.180.75.133 with SMTP id c5mr8084260wiw.2.1367308628871;
        Tue, 30 Apr 2013 00:57:08 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.211.201 with SMTP id ne9ls63928wic.51.gmail; Tue, 30 Apr
 2013 00:57:07 -0700 (PDT)
X-Received: by 10.180.72.227 with SMTP id g3mr21434829wiv.1.1367308627615;
        Tue, 30 Apr 2013 00:57:07 -0700 (PDT)
Original-Received: from mail-wi0-x22b.google.com (mail-wi0-x22b.google.com [2a00:1450:400c:c05::22b])
        by mx.google.com with ESMTPS id d13si8451211wjx.87.2013.04.30.00.57.07
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Tue, 30 Apr 2013 00:57:07 -0700 (PDT)
Received-SPF: pass (google.com: domain of tohari@gmail.com designates 2a00:1450:400c:c05::22b as permitted sender) client-ip=2a00:1450:400c:c05::22b;
Original-Received: by mail-wi0-f171.google.com with SMTP id l13so3595922wie.10
        for <std-proposals@isocpp.org>; Tue, 30 Apr 2013 00:57:07 -0700 (PDT)
X-Received: by 10.194.240.132 with SMTP id wa4mr47269906wjc.52.1367308627530;
 Tue, 30 Apr 2013 00:57:07 -0700 (PDT)
Original-Received: by 10.194.59.207 with HTTP; Tue, 30 Apr 2013 00:57:07 -0700 (PDT)
In-Reply-To: <7c79ca05-607f-40e8-bd51-467363f007ac@isocpp.org>
X-Original-Sender: tohari@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of tohari@gmail.com designates 2a00:1450:400c:c05::22b as permitted
 sender) smtp.mail=tohari@gmail.com;       dkim=pass header.i=@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:4098
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/4098>

--089e014939480adb8b04db8f5932
Content-Type: text/plain; charset=ISO-8859-1

> Personally, I don't think that default parameters are a "flawed feature".
> That being said, the flaws discussed are *not* resolved by your
> suggestion.
>
> Default parameters solve a simple, very specific problem. Function
> overloading solves a larger, more general problem. I like that we have
> both. And I think that the problem that you intend to solve, with some kind
> of "default" parameter, is best solved with the larger, more general
> solution.
>
> Also, with `optional`:
>
> void foo(int param, optional<type1> value1, optional<type2> value2) {
>   type1 val1 = value1.value_or(a1);
>   type2 val2 = value2.value_or(a2);
>   //implementation
> }
>
> void usefoo() {
>        foo(0, nullopt, b2);
> }
>
> That seems to take care of the problem.
>
>
This does not work.

//foo.h
void foo(int a, type1 param1, type2 param2 = value2);

//foo.cpp
void foo(int a, type1 param1, type2 param2) {
   //Is param1 value1 or value3?
}

//usefoo1.cpp
void foo(int a, type1 param1 = value1, type2 param2);
void usefoo1() {
     foo(1);
}

//usefoo2.cpp
void foo(int a, type1 param1 = value3, type2 param2);
void usefoo2() {
     foo(1);
}

From the above example it is clear that the caller decides the default
values with the function based on the latest declaration that is available
to it. So foo() cannot decide the default values.

Regarding the Lawrence' comment that default parameters being unnecessary:
We need to define as many overloaded functions as the number of default
parameters. Besides it will be hidden in the source and will not be
available if only the headers are available.

-- 

--- 
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.



--089e014939480adb8b04db8f5932
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><div class=3D"gmail_extra"><div class=3D"gmail_quote">=
<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-=
left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;p=
adding-left:1ex">
<div>Personally, I don&#39;t think that default parameters are a &quot;flaw=
ed feature&quot;. That being said, the flaws discussed are <i>not</i> resol=
ved by your suggestion.<br><br>Default parameters solve a simple, very spec=
ific problem. Function overloading solves a larger, more general problem. I=
 like that we have both. And I think that the problem that you intend to so=
lve, with some kind of &quot;default&quot; parameter, is best solved with t=
he larger, more general solution.<br>
<br>Also, with `optional`:<br><br><div style=3D"background-color:rgb(250,25=
0,250);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><div><=
span style=3D"color:rgb(0,0,136)">void</span><span style> foo</span><span s=
tyle=3D"color:rgb(102,102,0)">(</span><span style=3D"color:rgb(0,0,136)">in=
t</span><span style> param</span><span style=3D"color:rgb(102,102,0)">,</sp=
an><span style> optional</span><span style=3D"color:rgb(0,136,0)">&lt;type1=
&gt;</span><span style> value1</span><span style=3D"color:rgb(102,102,0)">,=
</span><span style> optional</span><span style=3D"color:rgb(0,136,0)">&lt;t=
ype2&gt;</span><span style> value2</span><span style=3D"color:rgb(102,102,0=
)">)</span><span style> </span><span style=3D"color:rgb(102,102,0)">{</span=
><span style><br>
=A0 type1 val1 </span><span style=3D"color:rgb(102,102,0)">=3D</span><span =
style> value1</span><span style=3D"color:rgb(102,102,0)">.</span><span styl=
e>value_or</span><span style=3D"color:rgb(102,102,0)">(</span><span style>a=
1</span><span style=3D"color:rgb(102,102,0)">);</span><span style><br>
=A0 type2 val2 </span><span style=3D"color:rgb(102,102,0)">=3D</span><span =
style> value2</span><span style=3D"color:rgb(102,102,0)">.</span><span styl=
e>value_or</span><span style=3D"color:rgb(102,102,0)">(</span><span style>a=
2</span><span style=3D"color:rgb(102,102,0)">);</span><span style><br>
=A0 </span><span style=3D"color:rgb(136,0,0)">//implementation</span><span =
style><br></span><span style=3D"color:rgb(102,102,0)">}</span><span style><=
br><br></span><span style=3D"color:rgb(0,0,136)">void</span><span style> us=
efoo</span><span style=3D"color:rgb(102,102,0)">()</span><span style> </spa=
n><span style=3D"color:rgb(102,102,0)">{</span><span style><br>
=A0 =A0 =A0 =A0foo</span><span style=3D"color:rgb(102,102,0)">(</span><span=
 style=3D"color:rgb(0,102,102)">0</span><span style=3D"color:rgb(102,102,0)=
">,</span><span style> nullopt</span><span style=3D"color:rgb(102,102,0)">,=
</span><span style> b2</span><span style=3D"color:rgb(102,102,0)">);</span>=
<span style><br>
</span><span style=3D"color:rgb(102,102,0)">}</span><span style><br></span>=
</div></code></div><br>That seems to take care of the problem.<br></div><di=
v class=3D""><div class=3D"h5">

<p></p></div></div></blockquote></div><br></div><div class=3D"gmail_extra" =
style>This does not work.</div><div class=3D"gmail_extra" style><br></div><=
div class=3D"gmail_extra" style>//foo.h</div><div class=3D"gmail_extra" sty=
le>
void foo(int a, type1 param1, type2 param2 =3D value2);<br></div><div class=
=3D"gmail_extra" style><br></div><div class=3D"gmail_extra">//foo.cpp</div>=
<div class=3D"gmail_extra"><div class=3D"gmail_extra">void foo(int a, type1=
 param1, type2 param2) {<br>
</div><div class=3D"gmail_extra" style>=A0 =A0//Is param1 value1 or value3?=
</div><div>}</div><div><br></div></div><div>//usefoo1.cpp</div><div>void fo=
o(int a, type1 param1 =3D value1, type2 param2);<br></div><div><div class=
=3D"gmail_extra">
void usefoo1() {<br></div><div class=3D"gmail_extra">=A0 =A0 =A0foo(1);</di=
v><div class=3D"gmail_extra">}</div></div><div class=3D"gmail_extra" style>=
<br></div><div class=3D"gmail_extra" style>//usefoo2.cpp<br></div><div clas=
s=3D"gmail_extra" style>
<div style>void foo(int a, type1 param1 =3D value3, type2 param2);<br></div=
><div style><div class=3D"gmail_extra">void usefoo2() {<br></div><div class=
=3D"gmail_extra" style>=A0 =A0 =A0foo(1);</div><div class=3D"gmail_extra" s=
tyle>}</div>
<div><br></div><div style>From the above example it is clear that the calle=
r decides the default values with the function based on the latest declarat=
ion that is available to it. So foo() cannot decide the default values.</di=
v>
<div style><br></div><div style>Regarding the Lawrence&#39; comment that de=
fault parameters being unnecessary: We need to define as many overloaded fu=
nctions as the number of default parameters. Besides it will be hidden in t=
he source and will not be available if only the headers are available.</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 />

--089e014939480adb8b04db8f5932--

.
