www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Typesafe Variadic Functions - syntax

reply Vathix <vathix dprogramming.com> writes:
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
parent "Unknown W. Brackets" <unknown simplemachines.org> writes:
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