On Sun, Jul 09, 2017 at 10:21:59PM +0000, FoxyBrown via Digitalmars-d-learn 
wrote:
> How can we iterate over a variadic and have it's index. I'll do
> different things depend on if it's an even or odd index, but seems to
> be no way to get it.

Easy:

        auto func(Args...)(Args args) {
                foreach (i, arg; args) {
                        if (i % 2) {
                                // even
                                ... // do something with arg
                        } else {
                                // odd
                                ... // do something with arg
                        }
                }
        }


T

-- 
"Real programmers can write assembly code in any language. :-)" -- Larry Wall

Reply via email to