enums

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 30 10:56:13 PDT 2014


On Fri, 30 May 2014 13:34:38 -0400, Philippe Sigaud via  
Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:

> 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.

You can as long as the value is known at compile time:

http://dpaste.dzfl.pl/5a710bd80ab0

-Steve


More information about the Digitalmars-d-learn mailing list