Hello!
Is there any way to overload operators for enumerations?
I'm having fun trying to implement a Tri-State Boolean and Optional types, but I'm forced to use a record type for operators. Records look a bit ugly, have performance, RTTI and published properties issues ...
Now, my code looks like this:
TriBoolEnum = (Unknown, ExactFalse, ExactTrue);
TriBoolSet = set of TriBoolEnum;
TriBool = record
private
FValue: TriBoolEnum;
public
class operator Initialize(out Value: TriBool);
class operator Implicit(const Value: Boolean): TriBool; static; inline;
class operator Implicit(const Value: TriBool): Boolean; static; inline;
class operator Implicit(const Value: TriBool): TriBoolEnum; static; inline;
class operator Implicit(const Value: TriBoolEnum): TriBool; static; inline;
class operator Equal(const L, R: TriBool): TriBool; static; inline;
class operator Equal(const L: Boolean; R: TriBool): TriBool; static; inline;
class operator Equal(const L: TriBool; R: Boolean): TriBool; static; inline;
class operator LogicalOr(const L, R: TriBool): TriBool; static; inline;
class operator LogicalOr(const L: Boolean; R: TriBool): TriBool; static; inline;
class operator LogicalOr(const L: TriBool; R: Boolean): TriBool; static; inline;
...
I want something like this:
TriBool = (Unknown, ExactFalse, ExactTrue);
TriBoolHelper = record helper for TriBool
class operator ...
It compiles, but overloading doesn't work.
Thanks in advance.