I have two types, call them A
and B
. I want to ensure that future developers do not change these types in such a way that they can compare equal.
To do so, I would like to add a unit test and a static_assert
that ensure this property. I am in c++03, and I have tried various template tricks like the following.
template <class Left, class Right>
struct can_compare_equal {
typedef char True;
typedef long False;
template <class U>
static U GetT() { Left* l; Right* r; return *r == *l; }
template <class U> static True test(typeof(&can_compare_equal<Left,Right>::GetT<U>));
template <class U> static False test(...);
enum { value = sizeof(test<True>(0)) == sizeof(char) };
};
Unfortunately I can't get it to compile correctly. Any advice?