www.digitalmars.com         C & C++   DMDScript  

D - Not as overloadable operator

reply "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
Are there plans for overloading the unary ! operator?

Lars Ivar Igesund
Nov 06 2003
parent reply "Walter" <walter digitalmars.com> writes:
"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
parent reply "Lars Ivar Igesund" <larsivi stud.ntnu.no> writes:
"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
Nov 07 2003
parent Andy Friesen <andy ikagames.com> writes:
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
Nov 07 2003