iterate over variadic

2017-07-09 Thread FoxyBrown via Digitalmars-d-learn
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.

Re: iterate over variadic

2017-07-09 Thread drug via Digitalmars-d-learn
10.07.2017 01:21, FoxyBrown пишет: 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. auto foo(Types...)() { foreach(T; Types) { // do what you need

Re: iterate over variadic

2017-07-09 Thread Lamex via Digitalmars-d-learn
On Sunday, 9 July 2017 at 22:21:59 UTC, FoxyBrown 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. import std.stdio; import std.typecons, std.meta; template indexedAllSatisfy(alia

Re: iterate over variadic

2017-07-10 Thread H. S. Teoh via Digitalmars-d-learn
On Sun, Jul 09, 2017 at 10:21:59PM +, 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) {

Re: iterate over variadic

2017-07-10 Thread ag0aep6g via Digitalmars-d-learn
On 07/10/2017 08:31 PM, H. S. Teoh via Digitalmars-d-learn wrote: if (i % 2) { // even odd ... // do something with arg } else { // odd even