On 1/30/15 1:29 AM, Foo wrote:
@nogc
@safe
T[n] s(T = Args[0], size_t n = Args.length, Args...)(auto ref Args args)
pure nothrow {
return [args];
}
@nogc
@safe
T[n] s(T, size_t n)(auto ref T[n] values) pure nothrow {
return values;
}
void main() {
pragma(msg, typeof(s(1, 2, 3)));
pragma(msg, typeof([1, 2, 3].s));
}
----
Compilation output:
int[3]
int[3]
You only have to type a dot between the array and the 's'.
Because of pure and nothrow and the low cost of the function call even
such a lousy thing like the DMD optimizer should be capable of inlining
such a function every time.
Thanks for this code, it's a lot nicer and simpler than mine. -- Andrei