Variadic template with template arguments in pairs
Anonymouse
asdf at asdf.net
Sat Sep 15 14:32:19 UTC 2018
On Wednesday, 12 September 2018 at 21:33:17 UTC, Paul Backus
wrote:
> Another alternative is to write the function recursively:
>
> void doByPair(T, Rest...)(string desc, T* valuePtr, Rest rest)
> {
> writefln("%s %s: %s", T.stringof, desc, *valuePtr);
> if (rest.length) doByPair(rest);
> }
Rest... is genius, I don't know why it never struck me before.
My current solution doesn't support having chunks of varying
sizes (ideally it would take 2 *or* 3), but the current use case
is okay with just pairs for now. I imagine I could keep the same
signature and just access a third argument with rest[0] and
recursing on rest[1..$].
Many thanks!
More information about the Digitalmars-d-learn
mailing list