This syntax regarding null checking baffles me

Paul Backus snarwin at gmail.com
Sun Jan 10 16:44:29 UTC 2021


On Sunday, 10 January 2021 at 14:40:04 UTC, kdevel wrote:
> On Sunday, 10 January 2021 at 10:42:48 UTC, Jonathan M Davis 
> wrote:
>
> [...]
>
>> IIRC, if the class overrides opCast for bool, then
>>
>>     if(c)
>>
>> will cast the object to bool and use the result for the if 
>> condition,
>
> Well, no:
>
> ```null.d
> import std.stdio: writeln;
> class C {
>    bool opCast ()
>    {
>       return true;
>    }
> }

Your opCast has the wrong signature. It should be:

     bool opCast(T : bool)()


More information about the Digitalmars-d mailing list