[Issue 5279] Function-static associative arrays

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 26 17:22:55 PST 2010


http://d.puremagic.com/issues/show_bug.cgi?id=5279



--- Comment #6 from Jonathan M Davis <jmdavisProg at gmx.com> 2010-11-26 17:21:30 PST ---
@nfxjfg
It's going to have to be able to do it for objects eventually. Yes, it's a
thorny problem, but it _can_ be done. The fact that it's a thorny problem is
the reason why it hasn't been done _yet_, but it will be done eventually.

@Bearophile
What I gathered what you were saying is that you were looking for a way to have
a static constructor initialize static local variables. Doing that would break
scoping rules.

However, re-reading your initial comment, it looks like what you want to have
happen is for the compiler to effectively set up a static constructor within
the function automatically which is not visible to the programmer. The compiler
would simply be smart enough to know that

static string[string] map1 = ["bar" : "spam"];


translates to something like

static string[string] map1;
static this()
{
    string[string] map1_temp;
    map1_temp["bar"] = "spam";
    map1 = map1_temp;
}


That's not an entirely bad idea, but it seems to me that since CTFE has to be
fixed to be able to handle this situation anyway, we might as well just fix
CTFE rather than have the compiler special case this situation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list