www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Overloading Operator !

reply Rob Atkinson <Robert.Atkinson gmail.com> writes:
I've been working on my own EBNF parser (basically a D version of boost's
spirit) but I just realised that you can't overload unary !

Walter, are there any plans to do overload additional operators?  The docs
state:
Future Directions
The operators =, !, ., &&, ||, ?:, and a few others will likely never be
overloadable.

If we're close to 1.0 should this be changed to "will not be overloadable"?
Or will some more squeeze in before 1.0?

I've already worked around ! with a slightly different syntax (which I think
is better than boost's) so I don't need unary !, just more of a general
question.
Oct 25 2006
next sibling parent "Chris Miller" <chris dprogramming.com> writes:
Overloading unary ! for classes is not a good idea because it should  
always check if the reference is null; however, I believe it should be  
overloadable for structs.

Supporting unary ! for structs can be as simple as using opEquals(bool).  
This could also allow if(mystruct).

I would currently use this feature in my dstring module to mimic D's  
if(array) (which is pretty much the same thing, a struct with fancy  
if(array) and if(!array) syntax - so why not give users this power for  
their [struct] types).
Oct 25 2006
prev sibling parent Walter Bright <newshound digitalmars.com> writes:
Rob Atkinson wrote:
 I've been working on my own EBNF parser (basically a D version of boost's
 spirit) but I just realised that you can't overload unary !

I'd really like to get a D implementation of Spirit!
 Walter, are there any plans to do overload additional operators?  The docs
state:
 Future Directions
 The operators =, !, ., &&, ||, ?:, and a few others will likely never be
 overloadable.
 
 If we're close to 1.0 should this be changed to "will not be overloadable"?
 Or will some more squeeze in before 1.0?
 
 I've already worked around ! with a slightly different syntax (which I think
 is better than boost's) so I don't need unary !, just more of a general
question.

I'd not count on it for now, too many other things on the plate.
Oct 25 2006