[phobos] cast(bool) vs. opUnary!"!"

Walter Bright walter at digitalmars.com
Tue Mar 9 13:48:04 PST 2010


What happened was I didn't want a dichotomy between "should I use 
conversion to bool or operator not?" so I thought it best to stick with 
a conversion to bool, and to not allow overloading of operator !.

Steve Schveighoffer wrote:
> In the latest dmd 2.041, cast!T was added, and if statements were changed to do:
>
> if(s) => if(cast!bool(s))
>
> What happened to if translating to:
>
> if(!!s)
>
> which translates to ! opUnary!("!).  Hm... that's a lot of !'s :)
>
> I thought that was the plan, at least it was in the book.  Is that going away?
>
> It does make more sense to use cast(bool) because opUnary!"!" could potentially return a non-bool value.
>
> -Steve
>
>
>
>       
>
>
>   


More information about the phobos mailing list