|
Boost : |
Subject: Re: [boost] [assert] static_assert envy
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-01-18 20:21:58
AMDG
On 1/18/2011 1:56 PM, Thomas Klimpel wrote:
> That's an interesting technique. I wondered before how Boost.Contract could achieve its tricks, but it probably doesn't even use this technique. However, wouldn't it be simpler to define
>
> #if defined(BOOST_DISABLE_ASSERTS)
> # define BOOST_ASSERT_CODE if(true) {} else
> #else
> # define BOOST_ASSERT_CODE if(false) {} else
> #endif
>
> and then write
>
> BOOST_ASSERT_CODE {
> if (!c1.empty()&& !c2.empty()) {
> BOOST_ASSERT_MSG(c1.front() ? c2.front() : def_val(), "something is wrong" );
> }
> }
>
> If a construct like this would be part of a Boost.Contract library, I certainly wouldn't object to it during a review. I'm not so sure whether I like it enough just of its own. But I certainly prefer it over BOOST_ASSERT_IF_MSG, because now I can write my assertion code in a language I already know, and it's just a single macro (more or less, we still have BOOST_DISABLE_ASSERTS and BOOST_ASSERT_MSG and all the related stuff).
>
There's really no need to get fancy.
#ifndef BOOST_DISABLE_ASSERTS
if (!c1.empty() && !c2.empty()) {
BOOST_ASSERT_MSG(c1.front() ? c2.front() : def_val(),
"something is wrong" );
}
#endif
works just fine.
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk