Heterogeneous Variadic Arguments with Other Arguments

evilrat evilrat666 at gmail.com
Sun Jul 14 06:05:13 UTC 2019


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




More information about the Digitalmars-d-learn mailing list