www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - can we replace the variadic function stuff with the tuple-feature?

reply dennis luehring <dl.soluz gmx.net> writes:
(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
Jan 23 2007
parent reply Xinok <xnknet gmail.com> writes:
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.
Jan 23 2007
parent BCS <ao pathlink.com> writes:
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
 

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.
Jan 23 2007