AS the value can be anything, I don't see how you can safely use one value as 'false' Some sort of composite type with a value and a flag; that way they get passed around together. Enzomatrix has the right idea, I think, because the class methods can make the flag use transparent to the user.
As a curiosity, here's a solution in the main language I work in, SystemVerilog. I can use a union that has a type-safeness tag:
typedef union tagged {
void Invalid;
int Valid;
} VInt;
VInt vi1, vi2;
...
vi1 = tagged Valid (23+34); // Create Valid int
vi2 = tagged Invalid; // Create an Invalid value
...
if (vi2 == tagged invalid) begin
do_stuff;
end else begin
do_other_stuff();
end
And so on. However, even though this solution exists I'd probably still go with a class because it's easier to make the methods enforce access policies. |