Compile time data structure

Marek Janukowicz marek at janukowicz.net
Thu Sep 19 12:12:10 PDT 2013


Ali Çehreli wrote:

> On 09/16/2013 01:24 PM, Marek Janukowicz wrote:
> 
>  >    static string[string] columns () {
> // ...
>  >    }
> 
> Although the function itself is static, it returns a dynamic value.
> 
>  >      foreach( attr, col; columns() ) {
>  >        __traits(getMember, me, attr) = typeof(__traits(getMember, me,
>  > attr)).init;
>  >      }
> 
> That foreach is a run-time foreach because columns()'s return value is a
> run-time value.
> 
> As far as I know, static foreach is only for tuples (or TypeTuples). If
> you can generate the AA as a tuple, then the foreach will be evaluated
> at compile time.

I read your articles about tuples and templates and it all now makes more 
sense (why is your book not linked on dlang.org? It is much better stuff for 
beginners than official D docs). However, there is still one thing I 
struggle with: how do I create a tuple at compile time if I'm getting 
information I want to put into it in a foreach? All the examples I found 
create a tuple with all it's attributes available, while I get mine in an 
iterative manner...

-- 
Marek Janukowicz


More information about the Digitalmars-d-learn mailing list