On Monday, 3 September 2012 at 09:24:42 UTC, Peter Alexander wrote:
On Monday, 3 September 2012 at 09:15:08 UTC, Chris Nicholson-Sauls wrote:
On Sunday, 2 September 2012 at 23:40:01 UTC, Peter Alexander wrote:

Consider:

myAssert(false, "%d", 1);

What is Args? "%d", 1 could refer to the optional arguments, or the variadic arguments. Both match.

Easy: the variadic arguments are not, themselves, optional. Match the variadic. This kind of problem is already solved in every language with "scattering" assignments, and other such features.

The variadic arguments are optional, as you can have zero arguments count as variadic.

Also, how can I override the optional arguments in this function if all arguments are matched as variadic?

They are not really optional. That the language fails to enforce this (or provide an eforcement, rather) is a shortcoming. Pretending for a moment that D supports one of two things:

1) Empty array stands in for empty variadic. Then, given arguments like func(R, V..., O=D) you would call it with func(foo, [], bar). Since a typesafe variadic is effectively a sugar-laden array (well a tuple really), I see no reason this shouldn't be feasible. First-class tuples would likely be even better.

2) Named parameters. Then it's func(foo, O: bar), and the variadic argument can indeed be optional, although the meaning is no different than in (1).

In reality, though, we have neither of these things. Even so, how often does this actually arise in practice (never has for me)? And given the OP's specific case (__FILE__ and __LINE__ params) I don't foresee any useful case for overriding the defaults.

Honestly, I sometimes think that the special treatment of __FILE__ and __LINE__ when used as defaults was not the best way to go. It might've been better implemented as hidden params, only generated by the compiler when actually used in the body.

Reply via email to