enums

Philippe Sigaud via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 30 10:34:38 PDT 2014


On Fri, May 30, 2014 at 7:28 PM, Ali Çehreli
<digitalmars-d-learn at puremagic.com> wrote:
> On 05/30/2014 08:30 AM, Russel Winder via Digitalmars-d-learn wrote:
>
>>          enum double p0 = 0.0045;
>
> As others have already said, p0 is a manifest constant. Interestingly, it
> can be thought of like a C macro, being pasted inside source code.
>
> Avoid enums for arrays and associative arrays as they are hidden performance
> sinks. The constant gets regenerated at runtime every time it is used in an
> expression.

I guess that, in an ideal world, immutable variables could be use at
compile-time (template arguments, etc). We could then ditch
'enums-as-manifest-constants'.The best of both worlds.

But what we have here is already quite good!



More information about the Digitalmars-d-learn mailing list