|
Boost : |
From: John Maddock (John_Maddock_at_[hidden])
Date: 2001-11-26 07:58:37
I've had a go at producing a version of BOOST_STATIC_ASSERT that produces a
user defined message in compiler error output, but which meets the same
requirements as BOOST_STATIC_ASSERT: that is that it produces neither code
nor data, and is usable at class, function or namespace scope.
here's the first attempt:
#define BOOST_STATIC_ASSERT_MSG(cond,msg) \
struct BOOST_JOIN(_,msg){ ::boost::STATIC_ASSERTION_FAILURE<(cond)> msg;
};\
typedef int BOOST_JOIN(msg,_typedef)[sizeof(BOOST_JOIN(_,msg))]
There is also a test program attached so you can see what kind of messages
it produces (you will need to uncomment one of the lines following an //
errror: comment). The typedef part of the implementation above is required
for g++ which doesn't generate an error inside template code otherwise.
You should see both the msg and BOOST_STATIC_ASSERT_FAILURE in the error
message output in most cases, but as ever it depends a lot on the compiler.
One known defect:
Borland refuses to inline functions containing BOOST_STATIC_ASSERT_MSG, I
guess this is easily fixed with a
#if defined(__BORLANDC__) && defined(_NDEBUG)
section.
Thoughts?
Comments?
- John Maddock
http://ourworld.compuserve.com/homepages/john_maddock/
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk