iterate over variadic

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 10 11:31:34 PDT 2017


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


More information about the Digitalmars-d-learn mailing list