Static foreach.

Bill Baxter wbaxter at gmail.com
Thu Nov 2 18:29:47 PST 2006


Walter Bright wrote:
> Jarrett Billingsley wrote:
> 
>> In any case, I was trying to come up with examples, but couldn't.. 
>> maybe it wouldn't be as useful as I thought. 
> 
> 
> It is an interesting idea, but I agree we should wait until a compelling 
> use case appears.

It's basically a typelist, no?
If so you should be able to find lots of examples for how it would be 
useful.

Here's one:

http://www.codeproject.com/cpp/TTLTyplist.asp?df=100&forumid=29952&exp=0&select=724784

A variant template.  Lets you do something like:

    typedef variant< my_type, double > mv;

You could replace the fixed-maximum number of fields in that code with 
an unlimited number, and replace all the recursively instatiated 
typelist code with a straightforward foreach.

Basically in C++ every template that processes a typelist has to do so 
recursively, but with a static foreach you should be able to the same in 
a more straightforward procedural manner.

--bb



More information about the Digitalmars-d mailing list