September 03, 2006
Hi,
just had some thoughts about casting and types.

--------------------------------
import std.string;
import std.stdio;

void giveparam(int a) {
    writefln("takeparam " ~ format(a));
}

void variadic( ... ) {
    if(_arguments[0] == typeid(int))
    giveparam(* cast(int *) _argptr);
    //else if(_arguments[0] == typeid(double))
    //... and so on
}
/*
given......................: _arguments[0]      == typeid(int)
if this would be possible..: ???(_arguments[0]) == int;

I could write giveparam like this:
giveparam(* cast(???(_arguments[0]) *) _argptr);

and would not be forced to do if-checking for all types
*/

void main() {
    variadic(1);
}
---------------------------------------

Is there a way to do this ? If not, could something like this be integrated to D ?


Thanks for your replies in advance.
Daniel
September 03, 2006
"Daniel919" <Daniel919@web.de> wrote in message news:edf3no$2u23$1@digitaldaemon.com...
> Hi,
> just had some thoughts about casting and types.
>
> ...
>
> Is there a way to do this ? If not, could something like this be
> integrated
> to D ?

The problem with this is that variadic functions are evaluated at runtime. What you want to do is cast the _argptr to a type, something which has to be determined at compile-time.  The only way to do runtime typing is using the TypeInfo classes, which is what typeid is for.

The solution to this would be templates that take variadic arguments, something that D can't do yet.