C++ is happy with it. You can even give it the right semantics:
#include <iostream>
#include <cstdlib>
#include <cassert>
using namespace std;
class Int
{
public:
int x;
Int () { }
Int (int z) : x (z) { }
};
class BoolRange
{
public:
bool value;
int left;
int right;
BoolRange() : value (false) { }
BoolRange (bool v, int l, int r)
: value (v), left (l), right (r) { }
operator bool ()
{
return value;
}
};
ostream& operator<< (ostream& out, Int i)
{
return out << i.x;
}
ostream& operator<< (ostream& out, BoolRange b)
{
return out << b.left << '[' << b.value << ']' << b.right;
}
BoolRange operator< (Int l, Int r)
{
return BoolRange (l.x < r.x, l.x, r.x);
}
BoolRange operator< (Int l, BoolRange r)
{
return r.value
? BoolRange (l.x < r.left, l.x, r.right)
: BoolRange ();
}
BoolRange operator< (BoolRange l, Int r)
{
return l.value
? BoolRange (l.right < r.x, l.left, r.x)
: BoolRange ();
}
BoolRange operator< (BoolRange l, BoolRange r)
{
return l.value && r.value
? BoolRange (l.right < r.left, l.left, r.right)
: BoolRange ();
}
// Test driven development!
int main ()
{
for (int i = 0; i < 1000000; ++i)
{
Int v = rand() % 100;
Int w = rand() % 100;
if (Int(1) < v < w < Int(10)) // Look here!
{
assert (1<v.x && v.x<w.x && w.x<10);
} else
{
assert (1>=v.x || v.x>=w.x || w.x>=10);
}
}
}