can we replace the variadic function stuff with the tuple-feature?
BCS
ao at pathlink.com
Tue Jan 23 13:43:25 PST 2007
Reply to Xinok,
> dennis luehring Wrote:
>
>> (just an idea)
>>
>> if we say that the parameterslist of a function is a
>> local-defined-and-typed tuple
>> (maybe D should handle function parameters with an tuple-like
>> concept)
>> couldn't we get rid of the (another) variadic function concept and
>> replace it with the variadic template stuff...
>> ciao dennis
>>
> Tuples no. Tuples are template based, so if you were to use a
> different set of types for arguments, it would require a new instance
> of the function. This can result in some very large EXEs for
> relatively simple programs. Could you imagine using a separate
> instance of writefln for every different set of arguments you
> provided?
>
> I would happily welcome a new concept which is more easily managed
> though.
>
How about somthing like runtime tuples (for lack of a beter name)
int writef(V... args)
{
foreach(arg;args)
{
switch(typeof(arg))
{
case char[]: ... break;
case int: ... break;
case real: ... break;
case Object: ... break;
case struct: ... break;
default: ... break;
}
}
}
The switch would act something like a specialized template or an is statement.
Each args type is compared against the case list using the same rules that
are used for overloading specialized template. The important thing being
that it is done at runtime, as is the tuple creation.
More information about the Digitalmars-d
mailing list