wrapping functions with variadic-parameter wrappers

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Wed Dec 5 07:40:44 PST 2012


A function with variadic template parameters is just a function which takes
a set of compile-time known parameters.
My goal is to have a non-template function taking variadic parameters.

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

This is necessary to be able to pass variables to functions without knowing
the type of the functions.


On Wed, Dec 5, 2012 at 7:33 PM, Jacob Carlborg <doob at me.com> wrote:

> 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
>



-- 
Bye,
Gor Gyolchanyan.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121205/089d2cea/attachment.html>


More information about the Digitalmars-d mailing list