Map one tuple to another Tuple of different type
H. S. Teoh via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 21 21:08:13 PDT 2014
On Tue, Jul 22, 2014 at 02:47:51AM +0000, Vlad Levenfeld via Digitalmars-d-learn wrote:
> On Monday, 21 July 2014 at 19:02:59 UTC, H. S. Teoh via Digitalmars-d-learn
> wrote:
> >functionality is desirable. Maybe we should rouse a racket on the
> >main D forum to either make staticIota public, or implement static
> >foreach. ;-)
>
> static switch would be so sick. I frequently find myself doing some
> compile-time branching with more than 2 branches or with an enum (like
> for policies/strategies/whatever). Compile-time case labels would
> clean that code up, and final switch would be a maintenance
> improvement as well.
>
> static while sounds cool, but how would it work? (as in use case, not
> implementation). The condition would have to be immutable, wouldn't
> it?
I don't know about use cases in general, but one place where it comes in
handy is in iterating over template argument lists ("type tuples").
Currently, I have to resort to:
Tuple!(int,int,int,int,int) fields;
foreach (i; staticIota!(0, n))
{
fields[i]++; // for example
}
Which is not bad for simple operations, but would be cleaner if we had
static while / static foreach.
T
--
We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the Internet, we know this is not true. -- Robert Wilensk
More information about the Digitalmars-d-learn
mailing list