On Friday, 28 February 2014 at 11:27:31 UTC, Mike wrote:
I recently saw the following line of code:

enum size = __traits(classInstanceSize, Foo);

Why "enum"? Is this the equivalent of "immutable auto" or something?

A "const" or "immutable" declaration would declare a constant variable - meaning, unless it is optimized out at a later point, it will end up in the data segment and have its own address. An enum declares a manifest constant - it exists only in the memory of the compiler. Manifest constants make sense when doing metaprogramming. Constant/immutable declarations make sense for values that will be used in multiple places by code at runtime.

Reply via email to