D - Not as overloadable operator
- Lars Ivar Igesund (2/2) Nov 06 2003 Are there plans for overloading the unary ! operator?
- Walter (3/4) Nov 06 2003 No, as it is built up from the other overloadable ops.
- Lars Ivar Igesund (10/14) Nov 07 2003 Ok, what would I need to overload so that something like this
- Andy Friesen (11/25) Nov 07 2003 I would say that an isEmpty property would be much better in this
Are there plans for overloading the unary ! operator? Lars Ivar Igesund
Nov 06 2003
"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.
Nov 06 2003
"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...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 IgesundAre there plans for overloading the unary ! operator?No, as it is built up from the other overloadable ops.
Nov 07 2003
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 IgesundI 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
Nov 07 2003