March 07, 2011 Re: Static Associative Array | ||||
---|---|---|---|---|
| ||||
On 3/7/11, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
>
Kidding, just kidding..
|
March 07, 2011 Re: Static Associative Array | ||||
---|---|---|---|---|
| ||||
On Sunday 06 March 2011 18:33:04 Andrej Mitrovic wrote:
> On 3/7/11, Jonathan M Davis <jmdavisProg@gmx.com> wrote:
>
>
> Kidding, just kidding..
That _did_ seem like a rather rude post for you...
- Jonathan M Davis
|
March 07, 2011 Re: Static Associative Array | ||||
---|---|---|---|---|
| ||||
Posted in reply to Peter Lundgren | On 03/07/2011 03:22 AM, Peter Lundgren wrote: > == Quote from Jonathan M Davis (jmdavisProg@gmx.com)'s article >> On Sunday 06 March 2011 14:05:04 Peter Lundgren wrote: >>> Can you define an associative array in a way that can be evaluated at >>> compile time like you can with non-associative arrays? >> I'm pretty sure not. I think that it's currently suffering the same fate as stuff >> like classes and is not yet able to be CTFEed. Some day... >> - Jonathan M Davis > > If not, then what is the D way to initialize a static field of a struct or class a > la Java's static initializer blocks? I don't mind constructing the associative > array at run-time if I have to, but I can't afford to do it more than the once needed. Use the module's <static this () {...}> clause: int[string] aa; static this () { aa = ["a":1, "b":2, "c":3]; } unittest { foreach (k,v ; aa) writefln("%s --> %s", k,v); } Note: you can have as many such ckauses as you like. Denis -- _________________ vita es estrany spir.wikidot.com |
March 07, 2011 Re: Static Associative Array | ||||
---|---|---|---|---|
| ||||
On 3/7/11, Jonathan M Davis <jmdavisProg@gmx.com> wrote: > On Sunday 06 March 2011 18:33:04 Andrej Mitrovic wrote: >> On 3/7/11, Jonathan M Davis <jmdavisProg@gmx.com> wrote: >> >> >> Kidding, just kidding.. > > That _did_ seem like a rather rude post for you... > > - Jonathan M Davis > Don't worry, I'd never be rude to my fellow D programmers out of the blue. Maybe that post was a semi-rant, but only half-serious. :) Anyway there's a nice SO post on enums here: http://stackoverflow.com/questions/4790652/enum-vs-immutable-in-d/4793684#4793684 |
Copyright © 1999-2021 by the D Language Foundation