Heterogeneous Variadic Arguments with Other Arguments

harakim harakim at gmail.com
Sun Jul 14 06:11:26 UTC 2019


On Sunday, 14 July 2019 at 06:05:13 UTC, evilrat wrote:
> On Sunday, 14 July 2019 at 03:51:14 UTC, harakim wrote:
>> I wanted to do this:
>> package int serialize(byte[] destination, int offset, T...)(T 
>> values)
>> ....
>
> Can't really tell what's going on without call site and what do 
> you exactly mean by "heterogeneous arguments with other 
> arguments", but this thing is syntax error. You declared a 
> template here, and template parameters (compile-time 
> parameters) must come first.
>
>    int serialize(T...)(byte[] destination, int offset, T values)
>
> This is the case if you wanted to pass that buffer at runtime, 
> not sure if you can do this with CT parameters, though it 
> shouldn't prevent you from forcing CTFE evaluation by assigning 
> result to another CT parameter or enum.
>
>
> But if by "other arguments" you mean passing different types 
> there is untyped variadics with a bit different behavior(see 
> [1])
>
>
> [1] 
> https://dlang.org/spec/function.html#d_style_variadic_functions

Thanks. That answered my question. I was hoping to do this:
int serialize(T...)(byte[] destination, int offset, T values)

And now I understand a lot more about variadic functions and type 
arguments.


More information about the Digitalmars-d-learn mailing list