Compile-time assertion?

c++

Solution

See `static_assert` (C++0x only); if on an older version, see Boost's `StaticAssert`.

Problem

Is there a way I can assert that two constant expressions are equal at compile time? e.g. I want this to cause a compile-time error ``` enum { foo=263, bar=264 }; SOME_EXPRESSION(foo,bar) ``` but I want this to not cause an error ``` enum { foo=263, bar=263 }; SOME_EXPRESSION(foo,bar) ``` edit: the above was simplified. My situation is more like some_other_file_I_dont_control.h: ``` class X { public: enum { foo=263 }; } ``` my_file.h: ``` enum { bar=something+somethingelse }; // bar should equal X::foo SOME_EXPRESSION(X::foo, bar) ```

Original source