Operator_Compare Boolean Only?

I’m attempting to make wrapper classes that exactly emulate the behavior and capabilities of Xojo’s built-in data types.

In doing so I’ve run across an issue implementing the comparison operator in the same manner as it’s implemented for certain data types.

For example in the case of Boolean values:

[code]Dim a As Boolean = true
Dim b As Boolean = false
Dim c As Boolean = true

MsgBox(Str(a = b)) // compiles and displays false
MsgBox(Str(a = c)) // compiles and displays true

MsgBox(Str(a < b)) // fails to compile and displays error message:
// “You have used an operator that is not compatible with the data types specified”[/code]

If I implement Operator_Compare for my Boolean wrapper then all of the comparison operators (=, <, >, <=, >=, <>) are automatically allowed. This is obviously nonsensical (except for the = or <> case) which is why the compiler issues an error when one attempts to compare Booleans values in such a way. How do I emulate that behavior, only allowing for the equality check and issuing the error upon the attempt to use any other relational operator? Is it even possible to do so?

I mean, obviously I could just not implement the Operator_Compare method, but the default equality check is simply on the reference, not the wrapped value like I’d desire…

I don’t know of a way to do what you’re looking to do. It would be nice if there was a way to limit Operator_Compare, perhaps with a #pragma or an attribute. In the meantime, either return “-1” if they are not equal, or throw a runtime exception.

A runtime exception might be the closest thing, but it seems a bit heavy-handed…I’ll probably just return a “1” (personal preference", haha) for now and put an explanatory comment in the method.

There really ought to be a feature request for this…

Create one?

I wouldn’t mind defining true to be greater than false so I could use <= as the logical implies operator, for example.