Let’s say I have 3 classes. I expect sizeof() each class to be exactly the same–say 512 bytes.
How can I use something like BOOST_STATIC_ASSERT to apply to all of them such that
- I only need to use
BOOST_STATIC_ASSERTin a single place (DRY principle) - Evaluated once at compile-time and not run-time
Note: we can use whatever C++ techniques we want (create more class , use inheritance, etc)
My naive solution is presented below:
class A { ...stuff }; BOOST_STATIC_ASSERT( sizeof(A) == 512 );
class B { ...stuff }; BOOST_STATIC_ASSERT( sizeof(B) == 512 );
class C { ...stuff }; BOOST_STATIC_ASSERT( sizeof(C) == 512 );
This seems to work with gcc 4.0.1 and boost 1.39: