|
Boost Users : |
Subject: Re: [Boost-users] [optional] How to make boost::optional throw if trying to access uninitialized value
From: Josh Kelley (joshkel_at_[hidden])
Date: 2009-07-09 16:31:33
On Thu, Jul 9, 2009 at 1:13 PM, <dariomt_at_[hidden]> wrote:
> 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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net