On Friday, 11 November 2016 at 18:33:09 UTC, Heisenberg wrote:
On Friday, 11 November 2016 at 17:07:50 UTC, John Colvin wrote:
I'm sure there are loads of corner cases this doesn't cover,
but:
template inPos(uint n, alias f)
{
auto inPos(Args...)(auto ref Args args)
{
return f(args[1 .. n+1], args[0], args[n+1 .. $]);
}
}
import std.stdio;
alias formatSecond = inPos!(1, writefln);
void main()
{
1.writeln(2,3,4,5);
1.inPos!(2, writeln)(2,3,4,5);
42.formatSecond("The answer is %d");
}
and of course you could easily develop more powerful templates
that could do any other order manipulations you like.
That might be a solution as well. Specifying the position near
the variable will make the code much more straightforward to
read though, while not forcing the programmer to declare
separate templates in order to specify the position of a
function's argument..
Not sure if either of those reasons are language-change worthy.