Is there are reason why
void f(T)(T[] params...) {}
can't be passed freely intermixed T's and array of T's such as
f(1,2,[3,4]);
or
f([1,2],3,[4],[5,6]);
?
Is there are reason why
void f(T)(T[] params...) {}
can't be passed freely intermixed T's and array of T's such as
f(1,2,[3,4]);
or
f([1,2],3,[4],[5,6]);
?
Because those are different types. A T[] p... means the language will construct an array from the arguments if it isn't already an array. So if it is a [], it leaves it alone, if not, it wraps [] around it.
f([1,2,3]) thus remains f([1,2,3]) and f(1,2,3) thus becomes f([1,2,3]). The compiler btw also knows the length already, which means it can statically allocate it (and it does).
But how would this rule apply to f([1,2], 3)? f([[1,2], 3]) is the wrong type. It could try to automatically flatten it, but how far is this supposed to go? The simple rule doesn't cover this.
And the simple allocation doesn't either, since the length of extra arrays given may not be known. So the compiler can't just statically allocate it anymore.
It is a type mismatch, breaking the simple rule, and has no easy answer for in-situ space allocation.