220 4058 <25d51458-9a2e-4607-9b1a-9d2a7be8df4e@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Hariharan Subramanian <tohari@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Default values in middle parameters in a function
Date: Mon, 29 Apr 2013 03:15:28 -0700 (PDT)
Lines: 115
Approved: news@gmane.org
Message-ID: <25d51458-9a2e-4607-9b1a-9d2a7be8df4e@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_3792_936000.1367230528048"
X-Trace: ger.gmane.org 1367230530 6574 80.91.229.3 (29 Apr 2013 10:15:30 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 29 Apr 2013 10:15:30 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCJZFFHTQQIBBQ4Q7GFQKGQEH6CZJLQ@isocpp.org Mon Apr 29 12:15:34 2013
Return-path: <std-proposals+bncBCJZFFHTQQIBBQ4Q7GFQKGQEH6CZJLQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oa0-f71.google.com ([209.85.219.71])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCJZFFHTQQIBBQ4Q7GFQKGQEH6CZJLQ@isocpp.org>)
	id 1UWl7M-0008TK-Om
	for gclcip-std-proposals@m.gmane.org; Mon, 29 Apr 2013 12:15:33 +0200
Original-Received: by mail-oa0-f71.google.com with SMTP id o17sf38433350oag.6
        for <gclcip-std-proposals@m.gmane.org>; Mon, 29 Apr 2013 03:15:31 -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=UgPcaozpLpJl05BHV3AusNNrrSG0d7y5HoP7s+rXMdQ=;
        b=gI6D9gkSfj0/hmNQ+Z69COnkKh3DItqHhlnpEcVEQBABmx7wFpZp9LGrzgRzgAl7hr
         iUI3EuhrxZWfn3hd+jJVkfcmpqf+G2aP4ZvGIqXGeIVJe9S+jd8am4mbavn0fFcg4NuY
         sdYfpzH0Pw5mW/X6AAxxPeuyS2QOkkNseawiqCMtSPjNbB4C7ePcoZrol1ta5qygl6eF
         3K3ltIThp10DJpYbOQt/3INzHxJFkOkgvadXBWWiucvQNiGSoMWm5hzqxjMv4R89A98q
         5VWulBhmS4fYxCcQmQdhctnT5n2gzEAz8Q4xbHnmcCQTpjd/Yvoonwu/Z3lmSTz4tEej
         +guA==
X-Received: by 10.50.7.74 with SMTP id h10mr1121120iga.0.1367230531486;
        Mon, 29 Apr 2013 03:15:31 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.22.99 with SMTP id c3ls176400igf.11.canary; Mon, 29 Apr
 2013 03:15:29 -0700 (PDT)
X-Received: by 10.50.25.33 with SMTP id z1mr121308igf.16.1367230529411;
        Mon, 29 Apr 2013 03:15:29 -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:4058
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/4058>

------=_Part_3792_936000.1367230528048
Content-Type: text/plain; charset=ISO-8859-1

Problem:
Change the default value of a default parameter in a function might result 
in a surprising behaviour. The problem is described below.
Consider the following function declaration & definition

//file1.h
void foo(int param, type1 value1 = a1, type2 value2 = b1);

//file1.cpp
#include "file.h"
void foo(int param, type1 value1, type2 value2) {
        //implementation
}

//file2.cpp
#include "file1.h"

void usefoo() {
       foo(0, a1, b2); //i want to pass b2 and hence i am passing the 
default value a1 also
}

It is often the case that during the lifecycle of the software the default 
value is changed to a2 from a1. This necessitates a change in the function 
usefoo(). As there is no compilation error it is very easy to miss this 
error. Even if the person knows that it should be changed it is a 
cumbersome manual process (change it in all the places) and hence error 
prone. This kind of change is not uncommon at all. Days of work gets wasted 
due to this.

Solution:
Introduce the default keyword during the function call. The function call 
becomes

void usefoo() {
       foo(0, default, b2);
}

Now, no matter what the change in the default value the usefoo function 
will not produce any surprise. It might seem that the mirror image of the 
problem exists. If a user wants to pass a1 then changing the default value 
to a2 will result in a problem. The problem can be solved like this below.

foo(0, default, b2); // if the user wants to pass whatever the default 
value is
foo(0, a1, b2);       // if the user wants to pass a1 no matter what the 
default value is

Addition of this functionality matches the user intent.

-- 

--- 
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_3792_936000.1367230528048
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div>Problem:</div><div>Change the default value of a default parameter in =
a function might result in a surprising behaviour. The problem is described=
 below.</div><div>Consider the following function declaration &amp; definit=
ion</div><div><br></div><div>//file1.h</div>void foo(int param, type1 value=
1 =3D a1, type2 value2 =3D b1);<div><br></div><div>//file1.cpp</div><div>#i=
nclude "file.h"</div><div>void foo(int param, type1 value1, type2 value2) {=
</div><div>&nbsp; &nbsp; &nbsp; &nbsp; //implementation</div><div>}</div><d=
iv><br></div><div>//file2.cpp</div><div>#include "file1.h"</div><div><br></=
div><div>void usefoo() {</div><div>&nbsp; &nbsp; &nbsp; &nbsp;foo(0, a1, b2=
); //i want to pass b2 and hence i am passing the default value a1 also</di=
v><div>}</div><div><br></div><div>It is often the case that during the life=
cycle of the software the default value is changed to a2 from a1. This nece=
ssitates a change in the function usefoo(). As there is no compilation erro=
r it is very easy to miss this error. Even if the person knows that it shou=
ld be changed it is a cumbersome manual process (change it in all the place=
s) and hence error prone. This kind of change is not uncommon at all. Days =
of work gets wasted due to this.</div><div><br></div><div>Solution:</div><d=
iv>Introduce the default keyword during the function call. The function cal=
l becomes</div><div><br></div><div><div>void usefoo() {</div><div>&nbsp; &n=
bsp; &nbsp; &nbsp;foo(0, default, b2);</div><div>}</div></div><div><br></di=
v><div>Now, no matter what the change in the default value the usefoo funct=
ion will not produce any surprise. It might seem that the mirror image of t=
he problem exists. If a user wants to pass a1 then changing the default val=
ue to a2 will result in a problem. The problem can be solved like this belo=
w.</div><div><br></div><div>foo(0, default, b2); // if the user wants to pa=
ss whatever the default value is</div><div>foo(0, a1, b2); &nbsp; &nbsp; &n=
bsp; // if the user wants to pass a1 no matter what the default value is</d=
iv><div><br></div><div>Addition of this functionality matches the user inte=
nt.</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_3792_936000.1367230528048--

.
