variadic args

novice2 sorry at noema.ail
Tue Dec 12 02:35:03 PST 2006


Thanx again.
Sorry for my dumbness.
But i specially emphasized that target function not my.
Alien/legacy/phobos code.
How i can create vWritef() for example?
As i see in std.stdio we have xwritef()
But it not accessible outside module :(

So i don't see other way to repassing variadic args to other
function else some "syntatic shugar" like

void foo(...)
{
  bar(...);
}

or something other syntax.

may be this problem is forced and not actual, but i meet this :)


== Quote from Bill Baxter (dnewsgroup at billbaxter.com)'s article
> 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
>      vBar(args);
> }
> 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
> }
> --bb



More information about the Digitalmars-d-learn mailing list