Variadic templates

Reiner Pope reiner.pope at REMOVE.THIS.gmail.com
Fri Nov 3 03:16:05 PST 2006


> Does that handle a variadic function in an interface, too?
> 
> interface ILogger
> {
>   void log_msg(char[] fmt, ...);
> }
> 
> --bb

No, I don't think it does. You could get away with this, though:

interface ILogger
{
   void log_msg_impl(char[] fmt, varargData data);
}

void log_msg(T...) (ILogger logger, char[] fmt, T t)
{
   auto data = getVarargData(t);
   logger.log_msg_impl(fmt, data);
}

If the implicit-this syntax sugar we have for arrays (which allows 
"foo".toupper) was allowed for all types, then this discrepancy would 
disappear, and you could write the call as if were a member function:

myLogger.log_msg("foo: %d", foo);

as opposed to

log_msg(myLogger, "foo: %d", foo);

Cheers,

Reiner



More information about the Digitalmars-d mailing list