AA literals/initialisation

Jonathan M Davis jmdavisProg at gmx.com
Mon Nov 11 04:13:48 PST 2013


On Monday, November 11, 2013 12:55:09 simendsjo wrote:
> On Monday, 11 November 2013 at 11:43:01 UTC, Dmitry Olshansky
> 
> wrote:
> > 11-Nov-2013 15:06, Manu пишет:
> >>    but enum works fine:
> >>    
> >>    enum priorityMap = [
> >>    
> >>         "1" : "blocker",
> >>         "2" : "critical",
> >>         "3" : "critical",
> >>         "4" : "major",
> >>         "5" : "major",
> >>         "6" : "major",
> >>         "7" : "minor",
> >>         "8" : "minor",
> >>         "9" : "trivial" ];
> >> 
> >> So it does... I didn't think of an enum AA ;)
> > 
> > ... copy pastes that literal everywhere, I'm sure you'll like
> > it ;)
> 
> Will it be copied even if you just use it ("1" in priorityMap),
> or only if you pass it around as a parameter or assign it to
> variables?

Every time you use an enum, it's replaced with its value. So, if an enum is an 
AA, then that literal is copy-pasted everywhere that the enum is used. So, it 
would almost certainly be foolish to use it anywhere other than to assign to a 
variable (and then all of the operations are done on the variable). Really, 
having an enum that's an AA is almost certainly a foolish thing to do. It's 
one case where the behavior of enums doesn't help and definitely hurts.

- Jonathan M Davis


More information about the Digitalmars-d mailing list