Enum AA with classes not allowed anymore?
bauss
jj_1337 at live.dk
Fri Oct 13 03:32:01 UTC 2017
On Wednesday, 11 October 2017 at 17:40:15 UTC, Jonathan M Davis
wrote:
> On Wednesday, October 11, 2017 17:05:19 Daniel Kozak via
> Digitalmars-d wrote:
>> so you can try to use static immutable insted of enum
>
> Yeah. Similarly, you could just have a regular function that
> you call at compile time that returns what you want (assuming
> that it's not being assigned to an enum) - then if it's just
> being used to generate something that you actually want to keep
> around after compiling, you're not stuck with the AA continuing
> to exist past compile time.
>
> I don't know that it will ever happen, but there has been talk
> of disallowing enums of anything that will allocate, because
> you pretty much never want that (since it will allocate every
> time it's used), and it's easy to do accidentally.
>
> - Jonathan M Davis
Yeah I ended up making property functions that returns the AA's
with what I want.
Ex.
@property string[string] myAA() {
string[string] aa;
// ... populate aa
return aa;
}
Because then I didn't have to change any places it was used.
Since it's compile-time it shouldn't matter too much that it
might be called multiple times and generate a new AA. There seem
to be no better way to cache it other than local variables where
it's used.
I did have one enum AA I could change to a static AA since it
wasn't called during compile-time, so I guess there were some
advantages by not being able to compile with latest version; like
I wouldn't have caught that mistake if I didn't come by this.
More information about the Digitalmars-d
mailing list