[Issue 6917] with() at global scope too

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Nov 24 08:27:42 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=6917



--- Comment #2 from bearophile_hugs at eml.cc 2013-11-24 08:27:41 PST ---
Such "static with" that doesn't create a new scope is also useful to define
constant arrays:

void main() {
    enum LongNamedEnum { A, B, C, D }
    const int[LongNamedEnum] foo =
        [LongNamedEnum.A: 10, LongNamedEnum.B: 20,
         LongNamedEnum.C: 30, LongNamedEnum.D: 40];
}


with is usually useful to write such array literals in a shorter space, but you
can't also define the assopciative array as const:

void main() {
    enum LongNamedEnum { A, B, C, D }
    /*const*/ int[LongNamedEnum] foo;
    with (LongNamedEnum)
        foo = [A: 10, B: 20, C: 30, D: 40];
}



void main() {
    enum LongNamedEnum { A, B, C, D }
    static with (LongNamedEnum)
        const int[LongNamedEnum] foo = 
            [A: 10, B: 20, C: 30, D: 40];
}

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


More information about the Digitalmars-d-bugs mailing list