Phobos: __FILE__ as template default parameter

pineapple via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 21 03:34:01 PDT 2016


On Tuesday, 21 June 2016 at 10:28:03 UTC, pineapple wrote:
> On Tuesday, 21 June 2016 at 02:59:44 UTC, ZombineDev wrote:
>> I think it would be good idea to take this even further:
>>
>> T4 foo(T4, T0, T1, Ts..., T2, T3)(T0 t0, T1 t1, Args args, T2 
>> t2, T3 t3)
>>
>> In other words, I think that the limitation that variadic 
>> template parameter list must be at the end of the function 
>> parameters is arbitrary and just a deficiency of the current 
>> implementation.
>
> I don't disagree with you, but this is a separate issue. If the 
> arguments trailing Args have default values (as they would in 
> the case of __FILE__, __LINE__) it will create ambiguity.
>
> void foo(Args...)(Args args, int n = 1);
>
> What happens if I do this? foo(1, 2, 3, 4); Is n 1 or 4?

Another thought: What if in this case the trailing arguments are 
always the default value? In this case n is /always/ 1, file and 
line would always be __FILE__ and __LINE__. This would be a more 
general solution and maybe not too intolerably ugly.


More information about the Digitalmars-d mailing list