Implicit conversion of struct to bool for if (s) operation ?

Mike Parker via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 7 17:53:23 PDT 2016


On Tuesday, 7 June 2016 at 22:28:57 UTC, Steven Schveighoffer 
wrote:
>>
>> It's news to me that while opCast for all other types is for 
>> explicit
>> casting, opCast for bool works for implicit casting.
>
> as ag0... mentioned in another thread, opCast is NOT implicitly 
> being invoked here, but rather explicitly.
>
> That is:
>
> bool x = someStruct; // error
> if(someStruct) // explicit opCast!bool
>

Documented under 'Boolean Operations' at 
http://dlang.org/spec/operatoroverloading.html#cast


More information about the Digitalmars-d-learn mailing list