this T / variadic template and interfaces

frame frame86 at live.com
Tue Oct 27 11:30:53 UTC 2020


On Tuesday, 27 October 2020 at 10:41:06 UTC, Jacob Carlborg wrote:
> On Tuesday, 27 October 2020 at 09:40:33 UTC, frame wrote:
>
>> Hmm, a question of design. Is there also a convenient way to 
>> pass the arguments to a template or get a Variant[] from it?
>
> Convenient, no not that I know of. You can use a type safe 
> variadic function that takes Variant, if you want to end up 
> with Variant[] anyway. It depends on how you want the API to 
> look like. Here are some examples:
>
> void foo(...);
> void bar(Variant[] args ...);
>
> foo(3, "foo", 'a'); // pass in the arguments as is
> bar(Variant(3), Variant("foo"), Variant('a')); // need to wrap 
> each argument in Variant
>
> The advantage of using the type safe variadic function is that 
> all the arguments are bundle into one array, make it easier to 
> work with.
>
> --
> /Jacob Carlborg

I tried the (...) thing - I ran into access violation by passing 
a slice like:

if (_arguments[i] == typeid(ubyte[])) {
   auto foo = va_arg!(ubyte[])(_argptr);
}

The same is working with variadic template. I am missing 
something?




More information about the Digitalmars-d-learn mailing list