Phobos: __FILE__ as template default parameter

ZombineDev via Digitalmars-d digitalmars-d at puremagic.com
Mon Jun 20 19:59:44 PDT 2016


On Monday, 20 June 2016 at 14:28:06 UTC, Jacob Carlborg wrote:
> On 2016-06-19 12:43, Dicebot wrote:
>
>> Yes. It is necessary because runtime parameter list is 
>> variadic -
>> template bloat in such cases is usually eliminated by 
>> forwarding to
>> another private method immediately turning file/line into 
>> first runtime
>> argument instead.
>
> Would it be a bad idea to allow this in the compiler:
>
> void foo(Args...)(Args args, string file = __FILE__, size_t 
> line = __LINE__);
>
> It wouldn't be possible to pass "file" or "line" when calling 
> "foo". But it's useful for the special default values, __FILE__ 
> and __LINE__.

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.
A fixed number of parameters proceeding or following a variadic 
list should all work equally well, even in combination with IFTI.

BTW, Ruby also allows to define methods with such parameters: 
foo(first_arg, *middle_arguments, last_arg)




More information about the Digitalmars-d mailing list