wrapping functions with variadic-parameter wrappers

Jacob Carlborg doob at me.com
Wed Dec 5 07:33:13 PST 2012


On 2012-12-05 11:01, Gor Gyolchanyan wrote:
> What's the best (least overhead and most portable and safe) way wrapping
> a function into a variadic-parameter function?
>
> For instance:
>
> long foo(int i, char c)
> {
>     /// ...
> }
>
> long bar(...)
> {
>      return foo(/* ??? */);
> }
>
> This is necessary for losing the parameter types, but still having the
> function callable with its expected parameters. I suspect this could be
> done using inline assembler and knowledge of the D ABI to achieve
> near-zero overhead.
>
> The wrapper can include dynamic type checking using the automatically
> passed _arguments array to ensure type safety.
>
> This is useful for dynamic dispatching.

It might not be want you need but a variadic template is the easiest 
solution:

long bar (Args ...) (Args args)
{
     return foo(args);
}

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list