Extending basic types - bool

inteja inteja at nosmalldreams.net
Fri Jan 19 05:11:01 PST 2007


How do I make my own boolean class that operates *exactly* the same as the basic D type bool, but with extended functionality? Primarily I'm interested in overloading && and || but this isn't possible in D. typedef and alias aren't sufficient as I need extra functionality.

To use my own Bool class, currently I need the following syntax:

Bool a = new Bool(true);
Bool b = new Bool(false);

Bool c = a.getValue() && b.getValue();

OR (by overloading functions with opCall):

Bool c = a() && b();

Either of the above still seem counterintuitive. I just want to be able to use:

Bool c = a && b;


Thanks in advance.

inteja





More information about the Digitalmars-d-learn mailing list