
From: Patrick Horgan
I can't agree. The macros reduce complexity by simplifying the boolean expressions and by being more descriptive, thus better expressing the author's intention. You have a certain logic, but what I meant was that BOOST_FAIL_MSG could be built in terms of BOOST_ASSERT. It adds another layer of indirection on top of it.
Yes, it does. It seems like you're talking more about complexity of making the tool, while I talk about complexity of using the tool. For me, seeing and understanding a line with BOOST_ASSERT_IF_MSG would be way easier than the equivalent BOOST_ASSERT with the boolean expression. Similarly, BOOST_FAIL_MSG("msg") would be telling me what's happening at a glance while BOOST_ASSERT(!"msg") or BOOST_ASSERT_MSG(false, "msg") would require a little bit more time to parse.
And one could argue that C++ casts may add complexity as well, e.g. when you have
const_cast<derived*>(dynamic_cast<const derived*>(const_base_ptr))
instead of
(derived *) const_base_ptr The first uses simpler parts though, to accomplish what the more complex old style cast could do in one fell swoop. You've made my point, the old style cast is much more complex containing much meaning that leads to confusion and error often as not.
Now you've made my point. ;-) Using BOOST_ASSERT (C cast) to express all the kinds of assertions (type conversions) is more complex in the same sense as it may lead to confusion and errors. This is why I'd like to have these macros (C++ casts) - to have simpler, more specialised code-building blocks. It doesn't matter whether the simpler is implemented in terms of the more complex or the other way round - the effect is what counts.
BOOST_FAIL_MSG would be like the old style cast in that is subsumes more intent without exposing it to you.
I think exactly the opposite: BOOST_FAIL_MSG functionality is a subset of BOOST_ASSERT functionality, just like any C++ cast is a subset of the C cast. By using the less general tool you communicate your intention more precisely. Best regards, Robert