Boost logo

Boost :

From: Marcin Kalicinski (kalita_at_[hidden])
Date: 2005-09-19 15:44:50


>> #include <boost/config.hpp>
>> #if defined(BOOST_MSVC) && defined(NDEBUG)
>> # define BOOST_ASSUME(e) { BOOST_ASSERT(e); if (e); else __assume(0); }
>
> There's a real problem with your solution, however: you evaluate
> the expression twice. Won't the simpler, more direct form work?

Of course, that was a silly mistake. It should be:

#include <boost/config.hpp>
#undef BOOST_ASSUME
#if defined(BOOST_MSVC) && defined(NDEBUG)
# define BOOST_ASSUME(e) { BOOST_ASSERT(e); __assume(e); }
#else
# define BOOST_ASSUME(e) BOOST_ASSERT(e)
#endif

I hope that is fine now.

>Interesting. I'd have thought that calling __assume(0) was
>useless, but it tells the optimizer that the else clause won't
>occur. I wonder if that will work at all or as well as
>BOOST_ASSERT(e); __assume(e);

It's not useless, see my previous posts in the thread for examples of code
generated with and without __assume(0).

cheers,
Marcin


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk