Overload of ! operator
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jun 25 22:29:30 PDT 2013
On Wednesday, June 26, 2013 07:15:19 Eric wrote:
> I should have also added that the overloaded ! method returns a
> class instance and not a bool.
Well, at that point, you're completely out of luck with regards to overloading
!. In general, D doesn't really support overloading operators in a manner that
doesn't match how the built-in types work. It does things like assume that <,
<=, >=, and > will act the same way that they do with the built-in types and
uses opCmp to extrapolate all of those operators. In some cases, you _can_
make overloaded operators return types that make it so that they don't
function anything like the built-in types (e.g. opBinary with + could return a
completely unrelated type that had nothing to do with the original type or
with addition), but in pretty much any case where the compiler can get away
with using the same overloaded operator for multiple operators, it does it.
So, a number of decisions were made to better support correctness with types
that actually try and overload operators to match what the built-in types do
without caring about how that would affect types that would try and overload
them to do unrelated stuff.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list