June 12, 2005 Typesafe Variadic Functions - syntax | ||||
---|---|---|---|---|
| ||||
The current syntax is cool, but I just thought of something interesting. void foo(int[0 .. 2] foovalues); would allow between 0 and 2 parameters for foovalues. void foo(int[4 .. 8] foovalues); allows between 4 and 8.. and the compiler would enforce this. The actual count would be found using foovalues.length. To allow infinite, use ...: void foo(int[3 ...] foovalues); which means 3 or more. Also, the current syntax could be adjusted to void foo(int[...] foovalues); to keep it all consistent. |
June 12, 2005 Re: Typesafe Variadic Functions - syntax | ||||
---|---|---|---|---|
| ||||
Posted in reply to Vathix | Well, you can currently do this:
void foo(int[3] foovalues ...)
{
}
Which is halfway what you want. But you can't use dynamic arrays with that.
-[Unknown]
> The current syntax is cool, but I just thought of something interesting.
> void foo(int[0 .. 2] foovalues);
> would allow between 0 and 2 parameters for foovalues.
>
> void foo(int[4 .. 8] foovalues);
> allows between 4 and 8.. and the compiler would enforce this. The actual count would be found using foovalues.length.
>
> To allow infinite, use ...:
> void foo(int[3 ...] foovalues);
> which means 3 or more.
>
> Also, the current syntax could be adjusted to
> void foo(int[...] foovalues);
> to keep it all consistent.
|
Copyright © 1999-2021 by the D Language Foundation