enum abuse
Mike
none at none.com
Fri Feb 28 04:12:33 PST 2014
On Friday, 28 February 2014 at 11:47:35 UTC, Dicebot wrote:
> 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?
>>
>> Mike
>
> enum creates compile-time placement constant. It does not
> create any symbol in resulting binary. Value of such enum gets
> pasted straight into the context when used.
>
> Most similar thing in C terms would have been `#define size
> __traits(classInstanceSize, Foo)`, alas from preprocessor
> issues not present in D :)
>
> It is idiomatic D way to force compile-time evaluation of
> expression.
Damn good explanation. I think I'll do a pull for this in the
docs. Thank you!
More information about the Digitalmars-d-learn
mailing list