Typesafe variadics in any position

Steven Schveighoffer schveiguy at yahoo.com
Tue Feb 26 14:09:53 PST 2013


On Tue, 26 Feb 2013 16:38:39 -0500, Vladimir Panteleev  
<vladimir at thecybershadow.net> wrote:

> On Tuesday, 26 February 2013 at 20:29:51 UTC, Steven Schveighoffer wrote:
>> Having a conversation about the design of the new std.process, I  
>> lamented that typesafe variadics must be the last element in the list  
>> of parameters.
>
> Could the idea be expanded into allowing optional arguments in front of  
> non-optional ones, when it is not ambiguous to do so?

I think so, technically, it's no different than using a variadic  
parameter, and then requiring exactly none or one element in the variadic  
argument spot.

The one dangerous thing I thought of is we currently allow two consecutive  
same-type optional parameters.  The issue there is if a type changes, a  
call to the function might silently bind different parameters.

So perhaps we would have to stick to situations that aren't already valid  
(such as your idea of having an optional parameter before a required one),  
and disallow functions to have consecutive like-typed optional parameters  
in those cases.  Not sure if it's worth it.  It would be confusing to  
allow consecutive like-typed optional parameters at the end, but not at  
the front.

-Steve


More information about the Digitalmars-d mailing list