Why do some T.init evaluate to true while others to false?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 27 11:03:23 PDT 2016


On 5/27/16 1:42 PM, ArturG wrote:
> On Friday, 27 May 2016 at 16:56:21 UTC, Steven Schveighoffer wrote:
>> Why are you expecting it to be?
>>
>> Won't work for enums with first elements that are non-zero either:
>>
>> enum foo : int {
>>  bar = 1;
>> }
>>
>> foo f;
>>
>> if(f) writeln("this will output too");
>>
>
>
> but by default it works you just changed the default so its ok that it
> doesnt work.

I didn't change the default. The default is to pick the first member and 
use that as the init value. I may not have even considered what foo.init 
might be when I was creating my enum.

-Steve


More information about the Digitalmars-d-learn mailing list