My thoughts & experiences with D so far, as a novice D coder
    Steven Schveighoffer 
    schveiguy at yahoo.com
       
    Wed Mar 27 10:36:46 PDT 2013
    
    
  
On Wed, 27 Mar 2013 13:32:06 -0400, deadalnix <deadalnix at gmail.com> wrote:
> On Wednesday, 27 March 2013 at 16:52:27 UTC, Nick Sabalausky wrote:
>> Honestly, I hate that, too. The problem is that enum is (unfortunately)
>> intended to do double-duty as a bitfield so you can do something like
>> this:
>>
>> enum Options
>> {
>>     FeatureA = 0b0000_0001;
>>     FeatureB = 0b0000_0010;
>>     FeatureC = 0b0000_0100;
>>     FeatureD = 0b0000_1000;
>>     // etc...
>> }
>>
>> // Use features A and C
>> auto myOptions = Options.FeatureA | Options.FeatureC;
>>
>> That possibility means that D *can't* check for validity as you suggest.
>>
>
> It can. myOptions is an int here, as Options would decay to its base  
> type.
No, it's not.  try it.  I thought as you did too until recently.
And before you go checking, it's not a bug, it's functioning per the spec.
-Steve
    
    
More information about the Digitalmars-d
mailing list