Mutable enums
so
so at so.so
Sun Nov 13 16:16:57 PST 2011
On Mon, 14 Nov 2011 02:09:40 +0200, Jonathan M Davis <jmdavisProg at gmx.com>
wrote:
> It depends entirely on what you're trying to do. If you understand how
> manifest constants work, then they can be quite advantageous. What you
> probably really want for arrays though is not an enum but just a const or
> immutable module variable.
>
> immutable a = [3, 1, 2];
>
> Otherwise, you're allocating a new array every time you use the enum.
> So, use
> a manifest constant when you want to avoid having it take up any memory
> but
> don't care about whatever allocations may occur when it's used (primitive
> types such as ints being a prime example), whereas if you want an actual
> memory location for the constant and/or want it to be allocated only
> once,
> then use variable rather than an enum.
>
> - Jonathan M Davis
Wait a second, it is definitely a bug. You can't modify an enum.
"immutable a = [3, 1, 2];" is practically "enum a = [3, 1, 2];".
More information about the Digitalmars-d-learn
mailing list