variadic args

Bill Baxter dnewsgroup at
Tue Dec 12 00:00:02 PST 2006

novice2 wrote:
> thanx Bill Baxter.
> but i don't need foreach...
> no need any *processing*
> just repassing to variadic function, not my, for example format
> (...) or writef(...)
> please, don't show me how to reimplement format with doFormat(),
> i already to do it. but it is ugly :)

Ok, then for you I'll make the special "lean and mean" version:

struct VArgs
     static VArgs opCall(TypeInfo[] arguments, va_list argptr)
         VArgs result;
         result.arguments = arguments;
         result.argptr = argptr;
         return result;
     TypeInfo[] arguments;
     va_list argptr;

void vFoo(VArgs args)
     // do the actual body of the function here

void foo(...)
     vFoo(VArgs(_arguments, _argptr));

void vBar(VArgs args)


void bar(...)
     vBar(VArgs(_arguments, _argptr));

The point is more that _arguments and _argptr belong together, so it 
makes sense to package them up into a single struct to pass them around 
together rather than always passing them as two separate arguments. 
Whether or not you want the struct to help with processing the arguments 
  is up to you.

Personally I wish that D would a) pass a struct like the above to 
variadic functions, and b) let users specify a name rather than giving 
access to them through magic parameter names.  Magic parameter names 
with underscores just look terribly hackish.   Instead we could have 
something like:

void bar(...args) {
    //use args.types[i], *args.argptr here


More information about the Digitalmars-d-learn mailing list