[Issue 24842] No ability to overload unary logial not operator
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Nov 6 00:56:02 UTC 2024
https://issues.dlang.org/show_bug.cgi?id=24842
--- Comment #7 from Mai Lapyst <info at lapyst.by> ---
> 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.
Sure it easy, after all, dlang has both the `std.traits.isNumeric` and
`std.traits.isScalar` templates that can detect numerical / scalar values,
which would be the only types one would expect `+` to work on anyway.
> If you need to "negate" some object, why not overload the unary operator "-" or "~"?
> ...
> If your usecase is only that you like to write "!" instead of something else ...
My usecase is that i find writing `-` (which is an arithmetic inverse) and `~`
(which is both an bit-wise inverse AND an concatination in dlang), much more
confusing to read when an boolish, logical negation is that what is wanted &
being done in-code.
I would also argue that it's more commonly understood that `!` means logical,
boolish inverse across languages.
--
More information about the Digitalmars-d-bugs
mailing list