9 Jul
2009
9 Jul
'09
8:31 p.m.
On Thu, Jul 9, 2009 at 1:13 PM,
I've seen in the docs that boost::optional asserts if you try to access an uninitialized value.
Is it possible to make it throw an exception instead? Even in release mode?
You can change BOOST_ASSERT's behavior by defining BOOST_ENABLE_ASSERT_HANDLER. See http://www.boost.org/doc/libs/1_39_0/libs/utility/assert.html for details. boost/assert.hpp can be included multiple times in a single translation unit, so if you want boost::optional to throw exceptions but other parts of Boost to still assert, you can define BOOST_ENABLE_ASSERT_HANDLER immediately before including boost/optional.hpp and undefine it immediately afterward. Josh Kelley