Operator overloading, structs

Derek Parnell derek at psych.ward
Thu Jun 4 03:33:26 PDT 2009


On Thu, 04 Jun 2009 10:06:45 +0300, Yigal Chripun wrote:

> Andrei Alexandrescu wrote:
>> Yigal Chripun wrote:
>>> your abstraction inversion example doesn't apply here. The problem I 
>>> see is the narrowing implicit cast, i.e. int values behave like 
>>> booleans. I have no problem with the reverse which is what your 
>>> example is about.
>> 
>> An int does not convert to bool implicitly. An int can be tested with 
>> "if", which is a different thing.
>> 
>> Andrei
> 
> that is an implicit cast.
> what I'm saying is that:
> 
>   int a = .. ;
>   if (a) { .. }
> 
> this should be a compiler error IMO.

I'm not agreeing with you, Yigal.

I think that the idiom you described is not equivalent to 

   if (a == TRUE) { .. }

but really 

   if (a != 0) { .. }

when 'a' is an integer of any size or sign. 

This should *not* be a compiler error as it is a convenient shorthand for
some coders. Personally, I try not to code this idiom because I find it
misleading in terms of self documentation ... but then I'm against using
goto as well ;-)


-- 
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell



More information about the Digitalmars-d mailing list