Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an the documentation for an old version of boost. Click here for the latest Boost documentation.


The header <boost/assert.hpp> defines the macro BOOST_ASSERT, which is similar to the standard assert macro defined in <cassert>. The macro is intended to be used in Boost libraries.

By default, BOOST_ASSERT(expr) is equivalent to assert(expr).

When the macro BOOST_DISABLE_ASSERTS is defined when <boost/assert.hpp> is included, BOOST_ASSERT(expr) is defined as ((void)0). This allows users to selectively disable BOOST_ASSERT without affecting the definition of the standard assert.

When the macro BOOST_ENABLE_ASSERT_HANDLER is defined when <boost/assert.hpp> is included, BOOST_ASSERT(expr) evaluates expr and, if the result is false, evaluates the expression

::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)

assertion_failed is declared in <boost/assert.hpp> as

namespace boost

void assertion_failed(char const * expr, char const * function, char const * file, long line);


but it is never defined. The user is expected to supply an appropriate definition.

As is the case with <cassert>, <boost/assert.hpp> can be included multiple times in a single translation unit. BOOST_ASSERT will be redefined each time as specified above.

<boost/assert.hpp> also defines the macro BOOST_VERIFY. It has exactly the same behavior as BOOST_ASSERT, except that the expression that is passed to BOOST_VERIFY is always evaluated. This is useful when the asserted expression has desirable side effects; it can also help suppress warnings about unused variables when the only use of the variable is inside an assertion.

Copyright 2002, 2007 by Peter Dimov. Distributed under the Boost Software License, Version 1.0. See accompanying file LICENSE_1_0.txt or copy at