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!

Reply via email to