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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 4 22:29:53 UTC 2024


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

Mai Lapyst <info at lapyst.by> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #3 from Mai Lapyst <info at lapyst.by> ---
> See language reference 21.2.1 "Boolean Operations"
I'm well aware of this section of the specs, but it's not an viable substitude
for what I'm propsing.

It's also not anywhere near the ability of overloading the `!` operator,
because this section uses a trick by simple converting it to a plain bool
beforehand via `opCast!(bool)()`. But when using this, any other information is
lost forever.

Like in the example I send with the inital comment; it contains additional
information which I cannot retrieve after the conversion to an plain boolean
value; but I **need** to somehow keep it since the type **itself** is boolish
(which means has an two-value state).

Again, what I want is to create an struct `FormatId("abc", true)` which when
negated using the d-native `!`-operator turns into an instance of
`FormatId("abc", false)`. This is simply not possible at the moment.

I can respect if this is not an usecase that dlang wishes to support, but I
feel the language then would limit itself unnessearily.

--


More information about the Digitalmars-d-bugs mailing list