Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 06, 2003 Not as overloadable operator | ||||
---|---|---|---|---|
| ||||
Are there plans for overloading the unary ! operator? Lars Ivar Igesund |
November 07, 2003 Re: Not as overloadable operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars Ivar Igesund | "Lars Ivar Igesund" <larsivi@stud.ntnu.no> wrote in message news:bodune$uo3$1@digitaldaemon.com... > Are there plans for overloading the unary ! operator? No, as it is built up from the other overloadable ops. |
November 07, 2003 Re: Not as overloadable operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "Walter" <walter@digitalmars.com> wrote in message news:boeohv$25u5$1@digitaldaemon.com... > > "Lars Ivar Igesund" <larsivi@stud.ntnu.no> wrote in message news:bodune$uo3$1@digitaldaemon.com... > > Are there plans for overloading the unary ! operator? > > No, as it is built up from the other overloadable ops. > Ok, what would I need to overload so that something like this could work: class Foo { overloaded op } if (!foo) doSomething; If foo is a container class, !foo could return true when empty. Lars Ivar Igesund |
November 07, 2003 Re: Not as overloadable operator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Lars Ivar Igesund | Lars Ivar Igesund wrote:
> Ok, what would I need to overload so that something like this
> could work:
>
> class Foo {
>
> overloaded op
>
> }
>
> if (!foo) doSomething;
>
> If foo is a container class, !foo could return true when empty.
>
> Lars Ivar Igesund
I would say that an isEmpty property would be much better in this specific case.
More generally, overloading unary not is rather dangerous, as it currently applies to the reference itself, and not the object it references.
if (!o) is synonymous with if (o !== null)
Making ! overloadadble would entail throwing that o !== null invariant into the mix, and therefore making if (!o) not only misleading, but valid code that could throw an assertion failure, like the == operator already does.
-- andy
|
Copyright © 1999-2021 by the D Language Foundation