[static_assert.hpp] Add BOOST_STATIC_ASSERT_MSG?

BOOST_STATIC_ASSERT predated C++0x static_assert, so it doesn't take advantage of static_assert's message argument when static_assert is available. It would break too much code to change BOOST_STATIC_ASSERT, but we can add a new macro that does take advantage of C++0x static_assert if available. After adding this to <boost/static_assert.hpp>: + #ifndef BOOST_NO_STATIC_ASSERT + # define BOOST_STATIC_ASSERT_MSG( B, Msg ) static_assert(B, Msg) + #else + # define BOOST_STATIC_ASSERT_MSG( B, Msg ) BOOST_STATIC_ASSERT( B ) + #endif This test program: #include <boost/static_assert.hpp> int main() { BOOST_STATIC_ASSERT_MSG( true, "should never fire" ); BOOST_STATIC_ASSERT_MSG( false, "should always fire" ); return 0; } Compiling with VC++ 10, which supports static_assert, produced: temp.cpp(7) : error C2338: should always fire Compiling with VC++ 9, which does not support static_assert, produced: temp.cpp(7) : error C2027: use of undefined type 'boost::STATIC_ASSERTION_FAILURE<x>' with [ x=false ] Comments? --Beman

Beman Dawes wrote:
BOOST_STATIC_ASSERT predated C++0x static_assert, so it doesn't take advantage of static_assert's message argument when static_assert is available.
It would break too much code to change BOOST_STATIC_ASSERT, but we can add a new macro that does take advantage of C++0x static_assert if available.
+1
+ #ifndef BOOST_NO_STATIC_ASSERT + # define BOOST_STATIC_ASSERT_MSG( B, Msg ) static_assert(B, Msg) + #else + # define BOOST_STATIC_ASSERT_MSG( B, Msg ) BOOST_STATIC_ASSERT( B ) + #endif
The abbreviated "MSG" seems out of place. I realize "BOOST_STATIC_ASSERT_MESSAGE" is very long, but it fits the pattern better. I could make it even worse by suggesting that "BOOST_STATIC_ASSERT_WITH_MESSAGE" would read better, particularly since the message isn't being asserted. _____ Rob Stewart robert.stewart@sig.com Software Engineer, Core Software using std::disclaimer; Susquehanna International Group, LLP http://www.sig.com IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

Stewart, Robert wrote:
Beman Dawes wrote:
BOOST_STATIC_ASSERT predated C++0x static_assert, so it doesn't take advantage of static_assert's message argument when static_assert is available.
It would break too much code to change BOOST_STATIC_ASSERT, but we can add a new macro that does take advantage of C++0x static_assert if available.
+1
+ #ifndef BOOST_NO_STATIC_ASSERT + # define BOOST_STATIC_ASSERT_MSG( B, Msg ) static_assert(B, Msg) + #else + # define BOOST_STATIC_ASSERT_MSG( B, Msg ) BOOST_STATIC_ASSERT( B ) + #endif
The abbreviated "MSG" seems out of place. I realize "BOOST_STATIC_ASSERT_MESSAGE" is very long, but it fits the pattern better. I could make it even worse by suggesting that "BOOST_STATIC_ASSERT_WITH_MESSAGE" would read better, particularly since the message isn't being asserted.
It would be nice to remain consistent boost test practice: BOOST_WARN_MESSAGE(predicate, message) BOOST_CHECK_MESSAGE(predicate, message) BOOST_REQUIRE_MESSAGE(predicate, message) BOOST_STATIC_ASSERT_MESSAGE(predicate, message) and didn't Beman just add a BOOST_ASSERT_MESSAGE(predicate, message) Jeff

AMDG On 1/27/2011 8:26 AM, Jeff Flinn wrote:
Stewart, Robert wrote:
+ #ifndef BOOST_NO_STATIC_ASSERT + # define BOOST_STATIC_ASSERT_MSG( B, Msg ) static_assert(B, Msg) + #else + # define BOOST_STATIC_ASSERT_MSG( B, Msg ) BOOST_STATIC_ASSERT( B ) + #endif
The abbreviated "MSG" seems out of place. I realize "BOOST_STATIC_ASSERT_MESSAGE" is very long, but it fits the pattern better. I could make it even worse by suggesting that "BOOST_STATIC_ASSERT_WITH_MESSAGE" would read better, particularly since the message isn't being asserted.
It would be nice to remain consistent boost test practice:
BOOST_WARN_MESSAGE(predicate, message) BOOST_CHECK_MESSAGE(predicate, message) BOOST_REQUIRE_MESSAGE(predicate, message)
BOOST_STATIC_ASSERT_MESSAGE(predicate, message)
and didn't Beman just add a
BOOST_ASSERT_MESSAGE(predicate, message)
No. He added BOOST_ASSERT_MSG. This is consistent with BOOST_MPL_ASSERT_MSG. In Christ, Steven Watanabe

Steven Watanabe wrote:
AMDG
On 1/27/2011 8:26 AM, Jeff Flinn wrote:
Stewart, Robert wrote:
+ #ifndef BOOST_NO_STATIC_ASSERT + # define BOOST_STATIC_ASSERT_MSG( B, Msg ) static_assert(B, Msg) + #else + # define BOOST_STATIC_ASSERT_MSG( B, Msg ) BOOST_STATIC_ASSERT( B ) + #endif
The abbreviated "MSG" seems out of place. I realize "BOOST_STATIC_ASSERT_MESSAGE" is very long, but it fits the pattern better. I could make it even worse by suggesting that "BOOST_STATIC_ASSERT_WITH_MESSAGE" would read better, particularly since the message isn't being asserted.
It would be nice to remain consistent boost test practice:
BOOST_WARN_MESSAGE(predicate, message) BOOST_CHECK_MESSAGE(predicate, message) BOOST_REQUIRE_MESSAGE(predicate, message)
BOOST_STATIC_ASSERT_MESSAGE(predicate, message)
and didn't Beman just add a
BOOST_ASSERT_MESSAGE(predicate, message)
No. He added BOOST_ASSERT_MSG. This is consistent with BOOST_MPL_ASSERT_MSG.
Ahh, I forgot about that one. So the _MSG has some precedence, and is closer related to the existing BOOST_MPL_ASSERT_MSG, than to the boost test, IMHO, of course. Jeff
participants (6)
-
Beman Dawes
-
Dean Michael Berris
-
Jeff Flinn
-
John Maddock
-
Steven Watanabe
-
Stewart, Robert