Variadic grouping
Meta
jared771 at gmail.com
Mon Jul 29 10:52:39 PDT 2013
On Monday, 29 July 2013 at 17:35:09 UTC, JS wrote:
> I don't think that is very robust notation but if it is then it
> would work.
>
> Using ';' makes it obvious the next group is starting.
I think using f(..., name = ...) is pretty obvious, and possibly
easier to spot in a list of commas than `;`.
> In your notation, it seems like there could be issues. What if
> T2 is a local variable, then is that an assignment? If there is
> no possible issues then I wouldn't mind having such a syntax...
> anything is better than nothing.
I don't think it would be an issue, as it would work the same way
as local variables in functions that shadow those in an outer
scope.
import std.stdio;
void main()
{
int x = 2;
int test1(int x, int y)
{
return x + y;
}
auto n = test1(0, 1);
//Prints 1
writeln(n);
}
As for templates, I think you currently can't define templates
inside a function, so that wouldn't be an issue. As for using
this notation in a template argument list, I believe it works the
same way for templates.
alias T1 = int;
template t(T1)
{
alias t = T1;
}
void main()
{
//Prints "string"
pragma(msg, t!string);
}
So the requisite variadic template:
alias T1 = TypeTuple!(int, string);
template t(@name("T1") T1..., @name("T2") T2...)
{
alias t = T1;
}
void main()
{
//Should print (double, char)
pragma(msg, t!(T1 = double, char, T2 = bool));
//Should print (int, string)
pragma(msg, T1);
}
More information about the Digitalmars-d
mailing list