<div dir="ltr">In contrast to those two examples where immutable can be used at compile time, what are some other cases where it is necessary to use enum instead of immutable?</div><div class="gmail_extra"><br><br><div class="gmail_quote">

On 31 May 2014 09:33, Andrej Mitrovic via Digitalmars-d-learn <span dir="ltr"><<a href="mailto:digitalmars-d-learn@puremagic.com" target="_blank">digitalmars-d-learn@puremagic.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

This has been asked so many times, is this info not on the website? We should have an article on the site explaining this in depth. OT: Sorry for top-quoting and over-quoting.<div class="HOEnZb"><div class="h5"><br><br>On Friday, May 30, 2014, monarch_dodra via Digitalmars-d-learn <<a href="mailto:digitalmars-d-learn@puremagic.com" target="_blank">digitalmars-d-learn@puremagic.com</a>> wrote:<br>


> On Friday, 30 May 2014 at 15:30:15 UTC, Russel Winder via Digitalmars-d-learn wrote:<br>>><br>>> I think I have no idea what D enums are about.<br>>><br>>> Bearophile's example of some code in an email on another thread uses:<br>


>><br>>>         enum double p0 = 0.0045;<br>>><br>>> Now I would have written:<br>>><br>>>         immutable double p0 = 0.0045;<br>>><br>>> or at the very worst:<br>>><br>


>>         const double p0 = 0.0045;<br>>><br>>> For me, enum means create an enumerated type. Thus "enum double" to<br>>> define a single value is just a contradiction.<br>>><br>>> Enlightenment required…<br>


><br>> The keyword "enum" stems from the enum hack in C++, where you use:<br>> enum {foo = 100}; //Or similar<br>><br>> As a way to declare a manifest constant known at compile time.<br>><br>> D simply "hijacked" the "enum" keyword to mean "manifest constant that is known at compile time".<br>


><br>> Compared to an immutable instance:<br>> * The immutable instance creates an actual reference-able object in your binary. The enum will not exist outside of the compilation (think of it as a higher order macro)<br>


> * immutable represents a value, which *may* be initialized at runtime. In any case, more often than not (I have observed), the compiler will refuse to use the immutable's value as compile-time known, and it won't be useable as a template parameter, or static if constraint.<br>


>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">   -=Miles Stoudenmire=-<br>   <a href="mailto:miles.stoudenmire@gmail.com" target="_blank">miles.stoudenmire@gmail.com</a><br>   <a href="mailto:emiles@pitp.ca" target="_blank">emiles@pitp.ca</a> <br>

   <a href="http://itensor.org/miles/" target="_blank">http://itensor.org/miles/</a><br></div>
</div>