How to properly use variadic templates (functions)?
rempas
rempas at tutanota.com
Tue Dec 21 17:56:36 UTC 2021
On Tuesday, 21 December 2021 at 17:33:09 UTC, Steven
Schveighoffer wrote:
>
> The reason your original isn't working is that indexing a list
> of differently-typed things cannot be done using a runtime
> index.
>
> I'd say that an inner function + static foreach + switch is the
> best way to convert from runtime to compile-time values. And in
> general, I would say having function templates that handle each
> arg type are usually conducive to clean and easy code.
>
> But in the case you are suggesting, as long as you don't need
> to iterate them out of order, what you can do is foreach the
> args tuple, and do something like:
>
> ```d
> foreach(arg; args)
> {
> writeUpToNextDelimeter(prompt); // updates prompt to point
> at next delimiter
> processArg(arg, prompt);
> }
> ```
>
> -Steve
Got that! Thanks a lot Steve!
More information about the Digitalmars-d-learn
mailing list