digitalmars.D - Typesafe Variadic Functions - syntax
- Vathix (12/12) Jun 12 2005 The current syntax is cool, but I just thought of something interesting.
- Unknown W. Brackets (6/21) Jun 12 2005 Well, you can currently do this:
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.
Jun 12 2005
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.
Jun 12 2005








"Unknown W. Brackets" <unknown simplemachines.org>