Rationale for not allowing overload of && and ||?
Nick Sabalausky
a at a.a
Wed Jun 18 13:16:41 PDT 2008
"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.
More information about the Digitalmars-d
mailing list