mixin alias
Jarrett Billingsley
kb3ctd2 at yahoo.com
Sun Dec 16 12:51:38 PST 2007
"Derek Parnell" <derek at psych.ward> wrote in message
news:jnak6l8ihhe1.k3tzm3in813z.dlg at 40tude.net...
> Is there any reason why the alias template parameter cannot be a literal?
>
>
> template Foo(alias b) {
> int X = b;
> }
>
> void main() {
> int y = 4;
> mixin Foo!(y); // This is okay
> mixin Foo!(4); // This fails to compile
> // "mixin Foo!(4) does not match any template declaration"
> }
>
This is correct. You can only alias things that have names; the number 3
does not have a name.
What's weird is that:
template Foo(alias b)
{
int X = b;
}
template Foo(int b)
{
int X = b;
}
void main()
{
int y = 4;
mixin Foo!(4); // OK
// mixin Foo!(y); // fails, matches multiple (???)
}
doesn't. Why does Foo!(y) match Foo(int)?
A (kind of dumb) workaround is:
template Foo(b...)
{
static assert(b.length == 1);
int X = b[0];
}
More information about the Digitalmars-d-learn
mailing list