Rationale for not allowing overload of && and ||?
Joe Gauterin
Joseph.Gauterin at googlemail.com
Mon Jun 23 04:38:54 PDT 2008
Brian Price Wrote:
> 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
>
So there's no real reason? Presumably it's just a hangover from when D didn't have the 'lazy' keyword or an aversion to overloading them due to the mess C++ makes of it.
More information about the Digitalmars-d
mailing list