Better syntax for varargs / variadic functions?

Bill Baxter dnewsgroup at billbaxter.com
Thu Oct 5 01:41:38 PDT 2006


Much better!

It seems very odd, though, that the opApply doesn't do the advancing of 
arg (the iw++ that next() does).   If opApply took care of that, then 
get() or value() would probably be a better name than next().

Then if the compiler would just pass you one of these objects with a 
name you specify, all would be gravy:

void foo(...Args)
{
    foreach(arg; Args)
    {
       if(arg.type == typeid(char[]))
       {
          char[] str;
          arg.get(str);
          printf("%.*s", str);
       }
       else if(arg.type == typeid(int))
       {
          int i;
          arg.get(i);
          printf("%d", i);
       }
       else
       {
          assert(0);
          return;
       }
    }
}

Then we'd really be cooking with gas.

--bb



More information about the Digitalmars-d mailing list