Rationale for not allowing overload of && and ||?

Brian Price blprice61 at yahoo.com
Wed Jun 18 14:58:14 PDT 2008


Jarrett Billingsley Wrote:

> "Brian Price" <blprice61 at yahoo.com> wrote in message 
> news:g3brj5$2370$1 at digitalmars.com...
> > Nick Sabalausky Wrote:
> >
> >> "Joe Gauterin" <Joseph.Gauterin at googlemail.com> wrote in message
> >> news:g3bpl0$1ujc$1 at digitalmars.com...
> >> > What is the rationale for not allowing overloading of && and ||? It 
> >> > seems
> >> > to me that, with the 'lazy' keyword, D is one of the few languages 
> >> > where
> >> > overloaded && and || can correctly implement short circuited 
> >> > evaluation.
> >>
> >> If I'm not mistaken, I think you can define an "implicit conversion from
> >> this class (or struct?) to ...".  So I assume the reason is, defining an
> >> implicit conversion to bool would effectively eliminate all (legitamate)
> >> reasons to overload && and ||. The only things that overloading && and ||
> >> could do that couldn't be accomplished (with better compatability across
> >> various types) would be things that would break the intended meaning of 
> >> &&
> >> and ||. Buy that's considered bad style when overloading operators 
> >> anyway.
> >>
> >
> > Bayesian and fuzzy logic both assign non boolean meanings to the 
> > operations and/or.  If you cannot overload && and || you cannot express 
> > such logic operations in a concise recognizable form.
> 
> & and |? 
> 
> 
That is, of course, the workaround.  However bitwise-and does not mean logical and, nor bitwise-or mean logical or, so you are forced to use a syntax that is semantically incorrect.  That is, if you want the convenience of using operators.

Brian




More information about the Digitalmars-d mailing list