[Issue 24842] No ability to overload unary logial not operator

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Nov 5 11:49:36 UTC 2024


https://issues.dlang.org/show_bug.cgi?id=24842

--- Comment #6 from Dominikus Dittes Scherkl <dominikus at scherkl.de> ---
(In reply to Mai Lapyst from comment #5)
> [...] if we use that logic, everybody would
> expect `+`  to only work on numerical values since it means "addition"
Yes, that would be desirable, but it's much harder to enforce, as it is not
easy to detect if something is "numeric" or not. At least D has the "~"
operator, so that is no more necessary to convolute addition and concatenation.

I think D found a good compromise by only forbidding things that are confusing
and at the same time really not necessary. If you need to "negate" some object,
why not overload the unary operator "-" or "~"? They are much more commonly
understood to produce some kind of inverse.

If your usecase is only that you like to write "!" instead of something else,
no matter how confusing that is for the reader of your code, I fear this will
not convince anybody to add such a "feature".

--


More information about the Digitalmars-d-bugs mailing list