variadic funtions
Jarrett Billingsley
kb3ctd2 at yahoo.com
Mon Feb 12 18:54:21 PST 2007
"Tomas Lindquist Olsen" <tomas at famolsen.dk> wrote in message
news:eqr8q3$1a4a$1 at digitalmars.com...
> Hi all.
> Does anyone know any tricks for passing all arguments of a variadic
> function
> to another?
>
> void foo(...)
> {
> // do something
> bar(...);
> }
>
> void bar(...)
> {
> writefln(...);
> }
>
> Thanx
Not with "normal" functions. Usually the convention is to declare "..." and
"TypeInfo[] arguments, va_list argptr" versions of your function so that
other variadic funcs can call it, like
void foo(...)
{
vfoo(_arguments, _argptr);
}
void vfoo(TypeInfo[] arguments, va_list argptr)
{
vbar(arguments, argptr);
}
void bar(...)
{
vbar(_arguments, _argptr);
}
void vbar(TypeInfo[] arguments, va_list argptr)
{
// The only way to do this..
dout.writefx(arguments, argptr, true);
}
With variadic templates, it becomes much more straightforward, although your
output code can become bloated:
void foo(T...)(T args)
{
bar(args);
}
void bar(T...)(T args)
{
writefln(args);
}
You can also look at std.boxer, though I haven't really seen that many
people use it for varargs..
More information about the Digitalmars-d-learn
mailing list