On Tuesday, 21 June 2016 at 10:34:01 UTC, pineapple wrote:
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.

It should work just like the regular expression .*.? - if all parameters after the variadic list have default values, then the list should capture all arguments and the last parameters use their default values. E.g. args is (1, 2, 3, 4) and n is 1 in your example. In general the strategy should be: the variadic list captures as much arguments as its constraints allow it to capture.

// regex: (\d*)(.)(.?)
// (pretend that \d means scalar type)
void foo(T1, T2, Args...)(Args args, T1 t1, T2 t2 = "default"w)
    if (allSatisfy!(isScalarType, Args))
{
    pragma (msg, Args, ", ", T1, ", ", T2);
}

foo(0, 0L, "asd");       // (int, long), string, wstring
foo("asd", "sdf");       // (), string, string
foo('c', new Object, 3); // (char), Object, int

Reply via email to